0
votes

Before i ask a new question, i have read few or more question about this, but i keep confuse.

I Compile my program with :

g++ -std=c++11 -Wall -O3 -fopenmp main.cpp -o main -D WITH_COUNTER -I /usr/local/src/pcm -L /usr/local/src/pcm -L /usr/local/lib

Then, i found the error :

main.cpp:(.text.startup+0x27e): undefined reference to PCM::getInstance()

main.cpp:(.text.startup+0x289): undefined reference to PCM::resetPMU()

main.cpp:(.text.startup+0x310): undefined reference to PCM::program(PCM::ProgramMode, void const*)

So, can anyone explain to me how to solve this?

1

1 Answers

1
votes

You don't actually link with the libraries themselves.

The -L option tells the linker to add a directory to its search-path, but the linker will not go through all libraries in its path to find which might be correct (there could be hundreds or even thousands).

Instead you need to explicitly specify libraries to link with using the -l (lower-case L) option.

For some example library foo, there will exist a file named libfoo.a or libfoo.so. To link with it you use -lfoo.

If the documentation for your library doesn't tell you which library you should link with, look for a suitable named file (as mentioned above) and use the correct option to link with the library.