gcc compiled library: can successfully link with, how come it's "undefined symbol" when run the program?

186 Views Asked by At

I have a source code of a library (MP4v2 to be specific but I don't think it matters).

The original source code compiles into libmp4v2.so (with configure, make, make install), and everything works fine.

The original source code has the following line of code in "file.h",

MP4V2_EXPORT
MP4FileHandle MP4CreateEx(const char* fileName);

The implementation of this function, is in a file called "mp4.cpp".

MP4V2_EXPORT is defined to be __attribute__((visibility("default")))

The MP4CreateEx works fine, and I can use this function and link with "-lmp4v2", and run the final compiled program without any problem.

I then created another function in "file.h",

MP4V2_EXPORT
MP4FileHandle MP4CustomCreateEx(const char* fileName);

The implementation is in "mp4.cpp" too.

After configure, make, and make install, I can compile my code (which uses MP4CustomCreateEx function) and link with "-lmp4v2" without problem.

But when I run it (by "./a.out"), then it says,

./a.out: symbol lookup error: ./a.out: undefined symbol: MP4CustomCreateEx

Note that with the same lib file, I can still use MP4CreateEx function and all other exported functions without any problem, only this MP4CustomCreateEx has problem.

Any hints on what may cause the undefined symbol problem? Thanks.

0

There are 0 best solutions below