Question

I want to use libx264 in one of my projects on windows. I compiled x264 with cygwin including the shared and static library. Everythin works out fine, also the static and dynamic libraries are properly installed in cygwin.

When trying to compile another project that uses libx264 (gcc ... -lx264) I get an error:

/cygdrive/c/Users/Erik/workspace/test/Debug/../main.cpp:406: undefined reference to `x264_param_default_preset(x264_param_t*, char const*, char const*)'
/cygdrive/c/Users/Erik/workspace/test/Debug/../main.cpp:425: undefined reference to `x264_param_apply_profile(x264_param_t*, char const*)'

The linker seems to have problem with my built libraries of libx264, but what is exactly wrong here? How can I correctly link x264?

The full build output looks like this:

Build of configuration Debug for project test **

make all 
Building target: test.exe
Invoking: Cygwin C++ Linker
g++ -L"/cygdrive/c/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib" -L"/cygdrive/c/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86" -L/usr/local/lib -o "test.exe"  ./main.o   -lx264.dll -lKernel32 -lUser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -ld3dx9d -ld3d9 -loleaut32 -luuid -lm
./main.o: In function `_Z8InitX264ii':
/cygdrive/c/Users/Erik/workspace/test/Debug/../main.cpp:406: undefined reference to `x264_param_default_preset(x264_param_t*, char const*, char const*)'
/cygdrive/c/Users/Erik/workspace/test/Debug/../main.cpp:425: undefined reference to `x264_param_apply_profile(x264_param_t*, char const*)'
collect2: ld returned 1 exit status
make: *** [test.exe] Error 1

**** Build Finished ****

Thanks for your help!

Was it helpful?

Solution

You're using C++, not C. x264 is a C library, the names are probably getting mangled.

Try

extern "C" {
    #include "x264.h"
}

--- old suggestions follow ---

Why are you linking aginst 'lx264.dll' anod not just 'lx264'?

Also, it looks like you're trying to link Microsoft .lib files in. Usually object files aren't binary-compatible between compilers/linkers... though it may be different on Cygwin. And according to your comment below, it is different... so nevermind.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top