I have the following files:
funcs.hpp:
#include "iostream"
void func(void);
funcs.cpp:
#include "iostream"
#include "funcs.hpp"
void func(void)
{
std::cout<< "Running func" << std::endl;
};
main.cpp:
#include "iostream"
extern void func(void);
int main(void)
{
std::cout<< "call func" << std::endl;
func();
return 1;
}
I compiled funcs.cpp into shared library via command:
g++ -fPIC -shared funcs.cpp -o libfuncs.so
Then I call
g++ main.cpp -L. -llibfuncs -o main.o
To link the shared library to main and compile but I get an error:
/usr/bin/ld: cannot find -llibfuncs: No such file or directory
collect2: error: ld returned 1 exit status
I follow the examples I saw on line exactly, I don't know what's going on.
So the issue was gcc assumes lib will be added to the library name, you need to remove the lib portion, the correct command is:
I think this is poorly documented.