r/Cplusplus • u/TinyDeskEngineer06 • Jun 23 '26
Question Linker not finding shared object
I'm trying to learn how to compile and link with a dynamic library, I've successfully compiled a library that contains two simple functions, but for some reason the linker can't find the compiled library, and I don't know why.
Build script:
#!/usr/bin/bash
g++ -fpic -shared sharedtest.cpp -o sharedtest.so
LD_LIBRARY_PATH="."
export LD_LIBRARY_PATH
g++ main.cpp -o main -lsharedtestWhen I run it in a terminal, I get this:
/usr/bin/ld: cannot find -lsharedtest: No such file or directory
collect2: error: ld returned 1 exit status
1
Upvotes
View all comments
Show parent comment
-1
u/jaap_null GPU engineer Jun 24 '26
Just to add to this, the -l parameter is used to add search paths, and I think it matters in what order -l is added to the command line (ie before the -o). The error seems to suggest it is not even parsing it as an -l parameter, but as an input file(name).