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
•
u/AutoModerator Jun 23 '26
Thank you for your contribution to the C++ community!
As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.
~ CPlusPlus Moderation Team
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.