Libav linking error: undefined references - linker
Here's my problem:
I built ffmpeg from source (version 1.2), the libav* libraries are in /usr/local/lib and they're static
I'm compiling a ns3 (www.nsnam.org) module, so my only control over the linker is through the env variable LINKFLAGS
In the source the headers are in a "extern C" block, so it's not the usual g++ name mangling
I set LINKFLAGS="-I/usr/local/include/libavformat -I/usr/local/include/libavcodec -I/usr/local/include/libavutil -L/usr/local/lib -lavformat -lavcodec -lavutil", and the linker can't seem to find any of the libav* functions I call (I get a lot of "undefined reference" and then "collect2: error: ld returned status 1"
Can anyone help me? Thanks...
edit: here are a few of the undefined reference messages:
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_guess_format'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_read_frame'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avformat_write_header'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_interleaved_write_frame'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_find_stream_info'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_register_all'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_init_packet'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avformat_alloc_context'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_dump_format'
./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avio_close'
edit2: here is the message I get after "build failed":
-> task in 'scratch-simulator' failed (exit status 1):
{task 53952272: cxxprogram scratch-simulator.cc.1.o -> scratch-simulator}
['/usr/bin/g++', '-I/usr/local/include/libavcodec', '-I/usr/local/include/libavformat/',
'-I/usr/local/include/libavutil/', '-L/usr/local/lib', '-I/usr/local
/include/libavcodec', '-I/usr/local/include/libavformat/', '-I/usr/local/include
/libavutil/', '-L/usr/local/lib', '-pthread', '-pthread', '-Wl,-z,relro',
'scratch/scratch-simulator.cc.1.o', '-o', '/home/fede/Thesis/ns-allinone-3.14.1
/ns-3.14.1/build/scratch/scratch-simulator', '-Wl,-Bstatic', '-Wl,-Bdynamic',
'-Wl,--no-as-needed', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.',
'-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.',
'-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.',
'-L.', '-L.', '-L.', '-L.', '-L.', '-L/usr/lib', '-lns3.14.1-test-debug', '-lns3.14.1-
csma-layout-debug', '-lns3.14.1-point-to-point-layout-debug', '-lns3.14.1-netanim-
debug', '-lns3.14.1-lte-debug', '-lns3.14.1-spectrum-debug', '-lns3.14.1-antenna-
debug', '-lns3.14.1-aodv-debug', '-lns3.14.1-dsdv-debug', '-lns3.14.1-dsr-debug',
'-lns3.14.1-mesh-debug', '-lns3.14.1-olsr-debug', '-lns3.14.1-csma-debug', '-lns3.14.1-
wimax-debug', '-lns3.14.1-applications-debug', '-lns3.14.1-virtual-net-device-debug',
'-lns3.14.1-uan-debug', '-lns3.14.1-energy-debug', '-lns3.14.1-flow-monitor-debug',
'-lns3.14.1-nix-vector-routing-debug', '-lns3.14.1-tap-bridge-debug', '-lns3.14.1-
visualizer-debug', '-lns3.14.1-internet-debug', '-lns3.14.1-bridge-debug', '-lns3.14.1-
point-to-point-debug', '-lns3.14.1-mpi-debug', '-lns3.14.1-wifi-debug', '-lns3.14.1-
buildings-debug', '-lns3.14.1-propagation-debug', '-lns3.14.1-mobility-debug',
'-lns3.14.1-config-store-debug', '-lns3.14.1-tools-debug', '-lns3.14.1-stats-debug',
'-lns3.14.1-emu-debug', '-lns3.14.1-topology-read-debug', '-lns3.14.1-network-debug',
'-lns3.14.1-qoe-monitor-debug', '-lns3.14.1-core-debug', '-lrt', '-lgsl',
'-lgslcblas', '-lm', '-ldl', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-latk-1.0',
'-lgio-2.0', '-lpangoft2-1.0', '-lpangocairo-1.0', '-lgdk_pixbuf-2.0', '-lcairo',
'-lpango-1.0', '-lfreetype', '-lfontconfig', '-lgobject-2.0', '-lglib-2.0', '-lxml2',
'-lpython2.7']
The libraries are C. The library headers don't include an extern "C" when compiled as C++. Do this in your C++ source:
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
Or, more generically, for mixed C and C++ source:
#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#ifdef __cplusplus
}
#endif
And you should be fine.
I had this problem with av_find_stream_info and the problem was this function was deprecated. The problem was I had two ffmpeg installation on the box, and it was reading header from one installation and was using libraries from different installation.
After removing system default library, the problem resolved.
UPDATE: For Ubuntu I did following:
$ sudo dpkg -r libavcodec53
$ sudo dpkg -r libavformat53
$ sudo dpkg -r libavutil51
$ sudo dpkg -r libswscale2
Just came across this question in my own searching.
In waf building system, you should use STLIB and STLIBPATH to denote static library name and path, instead of using LINKFLAGS. Note that you should set STLIB to list of static library names to use without prefix or extension.
In wscript file, add
conf.env.append_value("STLIBPATH", ["/usr/local/lib"])
conf.env.append_value("STLIB", ["av*,av**"])
Related
Linux C Makefile (FFmpeg) undefined reference to `curl_easy_init'
I did some changes to /libavformat/concat.c in the FFmpeg source. There I included libcurl. Internet says I have to add the following code to 'Makefile'. INCLUDE = -I/usr/local/include LDFLAGS = -L/usr/local/lib LDLIBS = -lcurl That did not work. I use this to build FFmpeg: make clean && ./configure --prefix=/usr --enable-gpl --enable-libmp3lame --enable-libx264 && make -j 4 Error: /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libavformat.a(concat.o): In function `concat_read': /root/ffmpeg_sources/ffmpeg/libavformat/concat.c:151: undefined reference to `curl_easy_init' /root/ffmpeg_sources/ffmpeg/libavformat/concat.c:155: undefined reference to `curl_easy_setopt' /root/ffmpeg_sources/ffmpeg/libavformat/concat.c:156: undefined reference to `curl_easy_perform' /root/ffmpeg_sources/ffmpeg/libavformat/concat.c:158: undefined reference to `curl_easy_getinfo' original Makefile: https://github.com/FFmpeg/FFmpeg/blob/master/Makefile Can you help me?
Use this to configure FFmpeg: ./configure --prefix=/usr --enable-gpl --enable-libmp3lame --enable-libx264 --extra-cflags='-I/usr/local/include' --extra-ldflags='-L/usr/local/lib -lcurl' Don't mess with the Makefile, FFmpeg's build system isn't quite standard and simple as most typical opensource projects' Makefiles.
Gstream ARM cross compilation
I want to write an embedded GStreamer application for an ARM processor. I have a Freescale enviroment,which contains installed gstream-0.10 & cross-compiler toolchain. I took a first Hello World application from GStream manual and tried to compile it by arm-poky-linux-gnueabi-gcc video_1.c -o basic-tutorial-1 pkg-config --cflags --libs gstreamer-0.10 My gstreamer-0.10.pc consists: prefix=/home/.../build_mx6q/tmp/sysroots/varsommx6q/usr exec_prefix=/usr libdir=/home/.../build_mx6q/tmp/sysroots/varsommx6q/usr/lib includedir=/home/.../build_mx6q/tmp/sysroots/varsommx6q/usr/include/gstreamer-0.10 toolsdir=${exec_prefix}/bin pluginsdir=/usr/lib/gstreamer-0.10 datarootdir=${prefix}/share datadir=${datarootdir} girdir=${datadir}/gir-1.0 typelibdir=${libdir}/girepository-1.0 Name: GStreamer Description: Streaming media framework Requires: glib-2.0, gobject-2.0, gmodule-no-export-2.0, gthread-2.0, libxml-2.0 Version: 0.10.36 Libs: -L${libdir} -lgstreamer-0.10 Cflags: -I${includedir}* Compilation result: warning: libffi.so.6, needed by /.../usr/lib/libgstreamer-0.10.so, not found (try using -rpath or -rpath-link) warning: libz.so.1, needed by /.../usr/lib/libgstreamer-0.10.so, not found (try using -rpath or -rpath-link) /home/.../usr/lib/libgobject-2.0.so: undefined reference to `ffi_type_pointer' /home/.../usr/lib/libxml2.so: undefined reference to `inflateEnd' /home/.../usr/lib/libxml2.so: undefined reference to `gzdirect#ZLIB_1.2.2.3' /home/.../usr/lib/libxml2.so: undefined reference to `gzclose' /home/.../usr/lib/libxml2.so: undefined reference to `deflate' /home/.../usr/lib/libgobject-2.0.so: undefined reference to `ffi_type_float' /home/.../usr/lib/libxml2.so: undefined reference to `inflateInit2_' /home/.../usr/lib/libxml2.so: undefined reference to `inflate' /home/.../usr/lib/libgobject-2.0.so: undefined reference to `ffi_type_void' /home/.../usr/lib/libxml2.so: undefined reference to `gzwrite' /home/.../usr/lib/libgobject-2.0.so: undefined reference to `ffi_type_sint64' /home/.../usr/lib/libxml2.so: undefined reference to `crc32' /home/.../usr/lib/libxml2.so: undefined reference to `deflateEnd' ... collect2: error: ld returned 1 exit status Something went wrong, but I don't understand what and where. I still need a help. Thank you.
Try this arm-poky-linux-gnueabi-gcc video_1.c -o basic-tutorial-1 ` pkg-config --cflags --libs gstreamer-0.10`
Undefined references everywhere, while trying to compile BluezTools?
I'm trying to compile BluezTools using the following command: ./autogen.sh && ./configure && make Here is a snippet of the output: obextransfer.c:(.text+0x4d5): undefined reference to `g_type_check_instance_cast' obextransfer.c:(.text+0x4f1): undefined reference to `dbus_g_proxy_disconnect_signal' obextransfer.c:(.text+0x4fd): undefined reference to `g_object_unref' obextransfer.c:(.text+0x50a): undefined reference to `g_free' obextransfer.c:(.text+0x517): undefined reference to `g_object_unref' obextransfer.c:(.text+0x528): undefined reference to `g_type_check_class_cast' lib/obexd/obextransfer.o: In function `obextransfer_cancel': obextransfer.c:(.text+0x56a): undefined reference to `g_type_check_instance_is_a' obextransfer.c:(.text+0x58a): undefined reference to `g_assertion_message_expr' lib/obexd/obextransfer.o: In function `obextransfer_get_dbus_object_path': obextransfer.c:(.text+0x5e2): undefined reference to `g_type_check_instance_is_a' obextransfer.c:(.text+0x602): undefined reference to `g_assertion_message_expr' lib/obexd/obextransfer.o: In function `_obextransfer_get_property': obextransfer.c:(.text+0x64f): undefined reference to `g_type_check_instance_cast' obextransfer.c:(.text+0x660): undefined reference to `g_type_name' obextransfer.c:(.text+0x66f): undefined reference to `g_type_name' obextransfer.c:(.text+0x6a3): undefined reference to `g_log' lib/obexd/obextransfer.o: In function `progress_handler': obextransfer.c:(.text+0x4af): undefined reference to `g_signal_emit' lib/obexd/obextransfer.o: In function `obextransfer_cancel': obextransfer.c:(.text+0x5ad): undefined reference to `dbus_g_proxy_call' lib/obexd/obextransfer.o: In function `obextransfer_get_dbus_object_path': obextransfer.c:(.text+0x619): undefined reference to `dbus_g_proxy_get_path' lib/obexd/obextransfer.o: In function `_obextransfer_get_property': obextransfer.c:(.text+0x6e7): undefined reference to `g_value_set_string' collect2: error: ld returned 1 exit status make[2]: *** [bt-monitor] Error 1 make[2]: Leaving directory `/home/[]/Downloads/bluez-tools-bluez-tools/src' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/[]/Downloads/bluez-tools-bluez-tools This is my first attempt as building a C project on Linux, where am I going wrong? Running Linux Mint 15 Olivia 64bit.
Do you have bluez and obexd installed? https://code.google.com/p/bluez-tools/#Requirements You could check the output of ./configure for any errors. Usually there is a configure.log or similar to grep for erros. I dont know about Mint package management, but you probably need some kind of obex*-dev package at least or install obex source yourself. EDIT Edited to answer the comment. I do not think the obexd-client is enough, but try this method and see if it is. Otherwise you need to look for some -dev packages like libglib2.0-cil-dev libglib2.0-dev and libdbus-glib-1-dev. (Those are the names on Ubuntu). Here is how I got it to compile (still emits warnings, though). Install a bunch of -dev packages for glib and dbus (ddg/google the functions that fail to link, so you see which libraries they are from). Execute pkg-config --libs --cflags dbus-1 dbus-glib-1 glib-2.0 Use the output of the command in the ./configure e.g.: env LIBS="-I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0" ./configure Execute make See also this question: Compilation error dbus-ping-pong
Fixed a similar problem by adding pkg-config --libs gtk+-2.0. Maybe helps someone.
Link to a library built with mingw on Cygwin
I have built libmysqlclient using mingw on Cygwin, so I get the ".a" file, but when I try to link with this file, it fails. My compiler is mingw, on GNU/Linux and I target Windows. Here is the command line to link the program (generated by automake) : i586-mingw32msvc-g++ -s -O1 -Wall -Wclobbered -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wsign-compare -Wtype-limits -Wuninitialized -mwindows -o .libs/valoisscan.exe App.o ConfigManager.o DialogConfig.o DialogRCDStart.o DialogAbout.o findFile.o MainFrame.o PanelScan.o PanelSearch.o MyException.o strWxStdConv.o libsqlendive.o PanelBase.o rc.o -mthreads -Wl,--subsystem -Wl,windows -mwindows -L/usr/i586-mingw32msvc//lib /usr/i586-mingw32msvc//lib/libwx_mswu_richtext-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_aui-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_xrc-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_qa-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_html-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_adv-2.8.a /usr/i586-mingw32msvc//lib/libwx_mswu_core-2.8.a /usr/i586-mingw32msvc//lib/libwx_baseu_xml-2.8.a /usr/i586-mingw32msvc//lib/libwx_baseu_net-2.8.a /usr/i586-mingw32msvc//lib/libwx_baseu-2.8.a -lwxregexu-2.8 -lwxexpat-2.8 -lwxtiff-2.8 -lwxjpeg-2.8 -lwxpng-2.8 -lwxzlib-2.8 -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 ticpp/.libs/libticpp.a mysqlwrapped/.libs/libmysqlwrapped.a -lmysqlclient -lstdc++ -mthreads Here are the linker errors : mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x12b): undefined reference to `_mysql_ping#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x17b): undefined reference to `_mysql_errno#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x1d5): undefined reference to `_mysql_error#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x2f0): undefined reference to `_mysql_num_rows#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x31e): undefined reference to `_mysql_insert_id#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x349): undefined reference to `_mysql_fetch_row#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x3bd): undefined reference to `_mysql_query#8' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x5da): undefined reference to `_mysql_free_result#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0xb8c): undefined reference to `_mysql_free_result#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0xd9c): undefined reference to `_mysql_free_result#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x1712): undefined reference to `_mysql_store_result#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x172b): undefined reference to `_mysql_fetch_field#4' mysqlwrapped/.libs/libmysqlwrapped.a(Query.o):Query.cpp:(.text+0x1962): undefined reference to `_mysql_fetch_field#4' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x3c2): undefined reference to `_mysql_options#12' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x129c): undefined reference to `_mysql_init#4' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x135d): undefined reference to `_mysql_real_connect#32' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x1405): undefined reference to `_mysql_real_connect#32' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x14c0): undefined reference to `_mysql_ping#4' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x155a): undefined reference to `_mysql_ping#4' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x15eb): undefined reference to `_mysql_close#4' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x1ad9): undefined reference to `_mysql_close#4' mysqlwrapped/.libs/libmysqlwrapped.a(Database.o):Database.cpp:(.text+0x1e1b): undefined reference to `_mysql_close#4' I tried strings libmysqlclient.a | grep _mysql_ping and it returned two results, so the lib looks valid. Command i586-mingw32msvc-objdump -x libmysqlclient.a | grep mysql_ping outputs [ 39](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x000012f0 _mysql_ping It might be important : my target for gcc is i586-mingw32msvc
Since you are using C++ you might need to wrap your inclusion of mysqlclient.h in an extern "C": extern "C" { #include <mysqlclient.h> } C++ name mangling might be renaming the symbols so they can't be found by the linker.
You might need to use -Wl,--enable-stdcall-fixup during linking to not link against the decorated stdcall functions. Most libraries tend to export undecorated symbols even though they are stdcall. Other flags to try are -Wl,--kill-at and -Wl,--add-stdcall-alias.
Unable to build zpipe.c (Zlib sample program)
I'm trying to build zpipe.c. I've installed zlib 1.2.5 via configure; make; make install. I've moved my zpipe.c file into the actual zlib-1.2.5 directory where it includes the zlib.h header file. This is what I get when I attempt to build: [sk#lldma zlib-1.2.5]$ gcc zpipe.c /tmp/ccZ2OBz0.o: In function `def': zpipe.c:(.text+0x3c): undefined reference to `deflateInit_' zpipe.c:(.text+0x8f): undefined reference to `deflateEnd' zpipe.c:(.text+0xe2): undefined reference to `deflate' zpipe.c:(.text+0x163): undefined reference to `deflateEnd' zpipe.c:(.text+0x1df): undefined reference to `deflateEnd' /tmp/ccZ2OBz0.o: In function `inf': zpipe.c:(.text+0x22d): undefined reference to `inflateInit_' zpipe.c:(.text+0x280): undefined reference to `inflateEnd' zpipe.c:(.text+0x2c1): undefined reference to `inflate' zpipe.c:(.text+0x312): undefined reference to `inflateEnd' zpipe.c:(.text+0x36e): undefined reference to `inflateEnd' zpipe.c:(.text+0x398): undefined reference to `inflateEnd' The README doens't say anything specific about building on Linux and I see that deflate.h and the other .h files are all located in the directory... The source to zpipe.c is here: http://www.zlib.net/zpipe.c Any ideas? TIA [sk#lldma zlib-1.2.5]$ ls adler32.c example64 infback.c Makefile.in watcom adler32.lo example64.o infback.lo make_vms.com win32 adler32.o example.c infback.o minigzip zconf.h amiga example.o inffast.c minigzip64 zconf.h.cmakein ChangeLog examples inffast.h minigzip64.o zconf.h.in CMakeLists.txt examplesh inffast.lo minigzip.c zlib2ansi compress.c FAQ inffast.o minigzip.o zlib.3 compress.lo gzclose.c inffixed.h minigzipsh zlib.3.pdf compress.o gzclose.lo inflate.c msdos zlib.h configure gzclose.o inflate.h nintendods zlib.map contrib gzguts.h inflate.lo old zlib.pc crc32.c gzlib.c inflate.o qnx zlib.pc.in crc32.h gzlib.lo inftrees.c README zpipe.c crc32.lo gzlib.o inftrees.h treebuild.xml zutil.c crc32.o gzread.c inftrees.lo trees.c zutil.h deflate.c gzread.lo inftrees.o trees.h zutil.lo deflate.h gzread.o libz.a trees.lo zutil.o deflate.lo gzwrite.c libz.so trees.o deflate.o gzwrite.lo libz.so.1 uncompr.c doc gzwrite.o libz.so.1.2.5 uncompr.lo example INDEX Makefile uncompr.o
The problem is not in the headers, it compiles fine. The problem is that the linker can't find the library functions. Try compiling with this: gcc zpipe.c -lz This will compile with libz.a or libz.so (depending on whether you are static or dynamically compiling), and if correct these object files should contain the missing functions.