Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

c++ - g++ Undefined Symbol Error using shared library

The symbol is in the file. I verified it using nm & grep but I still get the undefined symbol error when I run the compiled application. Other symbols in the shared library are working just fine. The header file declares it as extern and it is not in a conditional pre-processor block. I'm new to c/c++ so any experience with something like this would be appreciated.

There are a ton of related questions on StackOverflow, but everyone is listing source files and headers that don't mean anything to the actual context of the question. This is a general programming question: Why can't g++ link the symbol into my compiled application? Header definition checks ok, the symbol is in the shared library, and other symbols are working properly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to set your LD_LIBRARY_PATH environment variable to include the path to your development version of the library. This will ensure the run time linker (ld.so) will find it when you run your application.

Your build settings are fine but they don't affect what happens at run time. There are ways to "bake" paths into the executable at build time if you really want to. See the man page for ld.so to see how it searches for libraries.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...