I am porting an application that I developed in Linux to Windows and am having some issues when building the application. After making the necessary code changes, everything compiles fine (and when built as a debug build in Visual Studio, runs without any issues). I need to build this in MinGW, and I'm having linker errors when I try to link it against liboauth, which is also required for my project.
The command and its output are as follows:
gcc application.o service.o util.o json.o api.o -L/usr/local/lib -lcrypto -lssl -lcurl -ljansson -loauth -Wl -o application
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_sign_hmac_sha1_raw':
c:\lib\liboauth-0.9.4\src/hash.c:314: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:314: undefined reference to `HMAC'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_sign_rsa_sha1':
c:\lib\liboauth-0.9.4\src/hash.c:334: undefined reference to `BIO_new_mem_buf'
c:\lib\liboauth-0.9.4\src/hash.c:335: undefined reference to `PEM_read_bio_PrivateKey'
c:\lib\liboauth-0.9.4\src/hash.c:336: undefined reference to `BIO_free'
c:\lib\liboauth-0.9.4\src/hash.c:343: undefined reference to `EVP_PKEY_size'
c:\lib\liboauth-0.9.4\src/hash.c:346: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:346: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:347: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:348: undefined reference to `EVP_SignFinal'
c:\lib\liboauth-0.9.4\src/hash.c:352: undefined reference to `CRYPTO_free'
c:\lib\liboauth-0.9.4\src/hash.c:353: undefined reference to `EVP_PKEY_free'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_verify_rsa_sha1':
c:\lib\liboauth-0.9.4\src/hash.c:367: undefined reference to `BIO_new_mem_buf'
c:\lib\liboauth-0.9.4\src/hash.c:368: undefined reference to `PEM_read_bio_X509'
c:\lib\liboauth-0.9.4\src/hash.c:370: undefined reference to `X509_get_pubkey'
c:\lib\liboauth-0.9.4\src/hash.c:371: undefined reference to `X509_free'
c:\lib\liboauth-0.9.4\src/hash.c:375: undefined reference to `BIO_free'
c:\lib\liboauth-0.9.4\src/hash.c:384: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:384: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:385: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:386: undefined reference to `EVP_VerifyFinal'
c:\lib\liboauth-0.9.4\src/hash.c:387: undefined reference to `EVP_MD_CTX_cleanup'
c:\lib\liboauth-0.9.4\src/hash.c:388: undefined reference to `EVP_PKEY_free'
c:\lib\liboauth-0.9.4\src/hash.c:373: undefined reference to `PEM_read_bio_PUBKEY'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_body_hash_file':
c:\lib\liboauth-0.9.4\src/hash.c:405: undefined reference to `EVP_MD_CTX_init'
c:\lib\liboauth-0.9.4\src/hash.c:406: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:406: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:408: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:412: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:412: undefined reference to `EVP_MD_size'
c:\lib\liboauth-0.9.4\src/hash.c:413: undefined reference to `EVP_DigestFinal'
c:\lib\liboauth-0.9.4\src/hash.c:414: undefined reference to `EVP_MD_CTX_cleanup'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_body_hash_data':
c:\lib\liboauth-0.9.4\src/hash.c:422: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:422: undefined reference to `EVP_MD_size'
c:\lib\liboauth-0.9.4\src/hash.c:423: undefined reference to `EVP_MD_CTX_init'
c:\lib\liboauth-0.9.4\src/hash.c:424: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:424: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:425: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:426: undefined reference to `EVP_DigestFinal'
c:\lib\liboauth-0.9.4\src/hash.c:427: undefined reference to `EVP_MD_CTX_cleanup'
collect2: ld returned 1 exit status
make: *** [montools] Error 1
I have all of the required libraries in the lib path, and for some reason liboauth just cannot find the references to libssl and libcrypto. This all builds fine in Linux. Any ideas?
Update
Based on responses, I have updated my linker command so as to link the libraries in a different order. My new command is as follows:
gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto
This fixes this previous problem and presents a new set of linker errors:
gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xee0): undefined reference to `CreateDCA#16'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xeef): undefined reference to `CreateCompatibleDC#4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf08): undefined reference to `GetDeviceCaps#8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf23): undefined reference to `GetDeviceCaps#8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf44): undefined reference to `CreateCompatibleBitmap#12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf5b): undefined reference to `SelectObject#8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf7e): undefined reference to `GetObjectA#12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x1024): undefined reference to `BitBlt#36'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x103b): undefined reference to `GetBitmapBits#12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10b0): undefined reference to `SelectObject#8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10bb): undefined reference to `DeleteObject#4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10c8): undefined reference to `DeleteDC#4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10d5): undefined reference to `DeleteDC#4'
collect2: ld returned 1 exit status
make: *** [montools] Error 1
A quick google search returned that I should also link in the gdi32 library (for purposes unrelated to my tasks. The final command for the linker is then as follows:
gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto -lgdi32
Try this:
gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto
Related
I'm trying to cross compile a tiny program under Linux for win32. It uses libarchive, which is available in for mingw on my fedora 23 installation (all installed through dnf), but I get lots of linker errors.
Source: https://github.com/panzi/save_the_zazus
Compiler/linker output:
panzi#panzi save_the_zazus [master*]$ mkdir -p package/img
panzi#panzi save_the_zazus [master*]$ touch package/img/atlas0.png package/img/atlas1.png package/img/atlas2.png
panzi#panzi save_the_zazus [master*]$ make TARGET=win32 setup
mkdir -p build/win32 build/src
panzi#panzi save_the_zazus [master*]$ make TARGET=win32
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -Wall -Werror -Wextra -std=gnu11 -Ibuild/src -O2 -c src/save_the_zazus.c -o build/win32/save_the_zazus.o
xxd -i package/img/atlas0.png > build/src/package_img_atlas0_png.c
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -Wall -Werror -Wextra -std=gnu11 -Ibuild/src -O2 -c build/src/package_img_atlas0_png.c -o build/win32/package_img_atlas0_png.o
xxd -i package/img/atlas1.png > build/src/package_img_atlas1_png.c
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -Wall -Werror -Wextra -std=gnu11 -Ibuild/src -O2 -c build/src/package_img_atlas1_png.c -o build/win32/package_img_atlas1_png.o
xxd -i package/img/atlas2.png > build/src/package_img_atlas2_png.c
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -Wall -Werror -Wextra -std=gnu11 -Ibuild/src -O2 -c build/src/package_img_atlas2_png.c -o build/win32/package_img_atlas2_png.o
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -static -larchive build/win32/save_the_zazus.o build/win32/package_img_atlas0_png.o build/win32/package_img_atlas1_png.o build/win32/package_img_atlas2_png.o -o build/win32/save_the_zazus.exe
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x301): undefined reference to `archive_read_new'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x31d): undefined reference to `archive_read_support_filter_all'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x3cd): undefined reference to `archive_entry_free'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x3df): undefined reference to `archive_read_free'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x3ef): undefined reference to `archive_write_free'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x426): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x462): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x4a1): undefined reference to `archive_read_support_format_all'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x538): undefined reference to `archive_read_open_filename'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x545): undefined reference to `archive_write_new'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x557): undefined reference to `archive_write_set_format_zip'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x56b): undefined reference to `archive_write_set_options'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x581): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x5c9): undefined reference to `archive_write_open_filename'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x5d9): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x61e): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x67a): undefined reference to `archive_entry_new2'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x6ba): undefined reference to `archive_read_next_header2'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x6d0): undefined reference to `archive_entry_pathname'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x727): undefined reference to `archive_entry_new2'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x73d): undefined reference to `archive_entry_copy_pathname'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x74b): undefined reference to `archive_entry_perm'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x75a): undefined reference to `archive_entry_set_perm'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x762): undefined reference to `archive_entry_filetype'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x771): undefined reference to `archive_entry_set_filetype'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x77f): undefined reference to `archive_entry_mode'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x78e): undefined reference to `archive_entry_set_mode'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7a5): undefined reference to `archive_entry_set_size'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7b3): undefined reference to `archive_entry_uid'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7c3): undefined reference to `archive_entry_set_uid'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7d1): undefined reference to `archive_entry_gid'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7e1): undefined reference to `archive_entry_set_gid'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7ef): undefined reference to `archive_entry_mtime_nsec'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x803): undefined reference to `archive_entry_mtime'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x819): undefined reference to `archive_entry_set_mtime'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x82b): undefined reference to `archive_write_header'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x83b): undefined reference to `archive_entry_free'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x854): undefined reference to `archive_write_data'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x870): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x904): undefined reference to `archive_write_header'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x91a): undefined reference to `archive_entry_size'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x948): undefined reference to `archive_read_data'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x96c): undefined reference to `archive_write_data'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x988): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x9dd): undefined reference to `archive_write_add_filter_none'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0xa13): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0xa47): undefined reference to `archive_entry_free'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0xa8e): undefined reference to `archive_error_string'
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0xad6): undefined reference to `archive_error_string'
collect2: error: ld returned 1 exit status
Makefile:82: recipe for target 'build/win32/save_the_zazus.exe' failed
make: *** [build/win32/save_the_zazus.exe] Error 1
For this single source file program I just wrote a simple Makefile. The png files aren't in the repo (yet), so just create empty files for them if you try to compile. I tried dynamic and static linking (would prefer static so all I need to do is to pass on a .exe file). For this output I used -static -larchive and it doesn't complain about any missing libraries, but I get all those undefined references.
Add -static -larchive to the end of your command line and try again. The linker isn't getting the library to link against. I've found it needs to be last on the command line.
I've installed libudev-dev, I can see the file /usr/lib/x86_64-linux-gnu/libudev.so but when I run gcc -Wall -ludev -o test test.c I get following error..
opensourcegeek#box:~/project/udev_device_discovery$ gcc -Wall -ludev -o test test.c
/tmp/ccg6Ydod.o: In function `main':
test.c:(.text+0xa): undefined reference to `udev_new'
test.c:(.text+0x35): undefined reference to `udev_enumerate_new'
test.c:(.text+0x4a): undefined reference to `udev_enumerate_add_match_subsystem'
test.c:(.text+0x60): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x76): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x82): undefined reference to `udev_enumerate_scan_devices'
test.c:(.text+0x8e): undefined reference to `udev_enumerate_get_list_entry'
test.c:(.text+0xab): undefined reference to `udev_list_entry_get_name'
test.c:(.text+0xc2): undefined reference to `udev_device_new_from_syspath'
test.c:(.text+0xd2): undefined reference to `udev_device_get_parent'
test.c:(.text+0xe2): undefined reference to `udev_device_get_devnode'
test.c:(.text+0x105): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x119): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x13f): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x153): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x179): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x197): undefined reference to `udev_device_unref'
test.c:(.text+0x1a3): undefined reference to `udev_list_entry_get_next'
test.c:(.text+0x1be): undefined reference to `udev_enumerate_unref'
test.c:(.text+0x1ca): undefined reference to `udev_unref'
test.c:(.text+0x1cf): undefined reference to `udev_new'
test.c:(.text+0x1fa): undefined reference to `udev_enumerate_new'
test.c:(.text+0x20f): undefined reference to `udev_enumerate_add_match_subsystem'
test.c:(.text+0x225): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x23b): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x247): undefined reference to `udev_enumerate_scan_devices'
test.c:(.text+0x253): undefined reference to `udev_enumerate_get_list_entry'
test.c:(.text+0x270): undefined reference to `udev_list_entry_get_name'
test.c:(.text+0x287): undefined reference to `udev_device_new_from_syspath'
test.c:(.text+0x297): undefined reference to `udev_device_get_devnode'
test.c:(.text+0x2ba): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x2ce): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x2f4): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x308): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x32e): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x34c): undefined reference to `udev_device_unref'
test.c:(.text+0x358): undefined reference to `udev_list_entry_get_next'
test.c:(.text+0x373): undefined reference to `udev_enumerate_unref'
test.c:(.text+0x37f): undefined reference to `udev_unref'
collect2: error: ld returned 1 exit status
I don't usually run ubuntu, but same code works on my fedora(slightly older version of libudev) and also a pi which runs wheezy (older version of libudev).
The order is important, put the library name at the end of the compilation / linking line:
$ gcc -Wall -o test test.c -ludev
The error you see is a linker error, not because of any installation issues.. Move -ludev to the end of the command line option:
gcc -Wall -o test test.c -ludev
I have installed zbar library and gtk library on Raspberry,but when I compile the example zbargtk.c that provided by the zbar,it can't be compiled.
The command I used is gcc -o testgtk testgtk.c pkg-config --libs --cflags gtk+-2.0 zbar.
I have spent three days to deal this problem,but I can't solve it.
Here are the errors i get:
pi#raspberrypi ~/Desktop $ gcc -o testgtk testgtk.c `pkg-config --libs --cflags gtk+-2.0 zbar`
testgtk.c: In function ‘main’:
testgtk.c:149:5: warning: ‘g_thread_init’ is deprecated (declared at /usr/include/glib-2.0/glib/deprecated/gthread.h:261) [-Wdeprecated-declarations]
/tmp/ccF6LqbT.o: In function `video_enabled':
testgtk.c:(.text+0x12c): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x148): undefined reference to `zbar_gtk_get_video_enabled'
testgtk.c:(.text+0x154): undefined reference to `zbar_gtk_get_video_opened'
/tmp/ccF6LqbT.o: In function `video_opened':
testgtk.c:(.text+0x1dc): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x1f8): undefined reference to `zbar_gtk_get_video_opened'
testgtk.c:(.text+0x204): undefined reference to `zbar_gtk_get_video_enabled'
/tmp/ccF6LqbT.o: In function `video_changed':
testgtk.c:(.text+0x2b8): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x300): undefined reference to `zbar_gtk_set_video_device'
/tmp/ccF6LqbT.o: In function `status_button_toggled':
testgtk.c:(.text+0x320): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x33c): undefined reference to `zbar_gtk_get_video_opened'
testgtk.c:(.text+0x348): undefined reference to `zbar_gtk_get_video_enabled'
testgtk.c:(.text+0x378): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x398): undefined reference to `zbar_gtk_set_video_enabled'
/tmp/ccF6LqbT.o: In function `open_button_clicked':
testgtk.c:(.text+0x55c): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x57c): undefined reference to `zbar_gtk_scan_image'
/tmp/ccF6LqbT.o: In function `main':
testgtk.c:(.text+0x620): undefined reference to `g_thread_init'
testgtk.c:(.text+0x708): undefined reference to `zbar_gtk_new'
testgtk.c:(.text+0x920): undefined reference to `scan_video'
collect2: ld returned 1 exit status
I'm working on ubuntu 14.04 LTS and am working on a shading example program. I have the following makefile:
CC=gcc
CFLAGS=-Wall -I/usr/X11R6/include
LDFLAGS=-pthread -L/usr/X11R6/lib -lm -lGL -lglut
OBJS=main.o scene.o shader.o
glsl_lighting: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o glsl_lighting
clean:
rm -f glsl_lighting
rm -f $(OBJS)
main.o: main.c
scene.o: scene.c
shader.o: shader.c
With the first few lines of the main file being:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "opengl.h"
This gave the following error:
gcc -pthread -L/usr/X11R6/lib -lm -lGL -lglut main.o scene.o shader.o -o glsl_lighting
main.o: In function `handleKeyPress':
main.c:(.text+0x27): undefined reference to `glutDestroyWindow'
main.o: In function `setPerspective':
main.c:(.text+0x65): undefined reference to `tanf'
main.c:(.text+0x144): undefined reference to `glMultMatrixf'
main.o: In function `main':
main.c:(.text+0x168): undefined reference to `glutInit'
main.c:(.text+0x172): undefined reference to `glutInitDisplayMode'
main.c:(.text+0x185): undefined reference to `glutInitWindowSize'
main.c:(.text+0x18f): undefined reference to `glutCreateWindow'
main.c:(.text+0x19f): undefined reference to `glutDisplayFunc'
main.c:(.text+0x1a9): undefined reference to `glutIdleFunc'
main.c:(.text+0x1b3): undefined reference to `glutKeyboardFunc'
main.c:(.text+0x1c4): undefined reference to `glClearColor'
main.c:(.text+0x1d1): undefined reference to `glClearDepth'
main.c:(.text+0x1db): undefined reference to `glDisable'
main.c:(.text+0x1e5): undefined reference to `glEnable'
main.c:(.text+0x1ef): undefined reference to `glDepthFunc'
main.c:(.text+0x1f9): undefined reference to `glEnable'
main.c:(.text+0x203): undefined reference to `glFrontFace'
main.c:(.text+0x20d): undefined reference to `glCullFace'
main.c:(.text+0x217): undefined reference to `glMatrixMode'
main.c:(.text+0x21c): undefined reference to `glLoadIdentity'
main.c:(.text+0x25c): undefined reference to `glMatrixMode'
main.c:(.text+0x266): undefined reference to `glutMainLoop'
scene.o: In function `createCylinder':
scene.c:(.text+0xf6): undefined reference to `cosf'
scene.c:(.text+0x147): undefined reference to `sinf'
scene.c:(.text+0x179): undefined reference to `cosf'
scene.c:(.text+0x1ca): undefined reference to `sinf'
scene.c:(.text+0x201): undefined reference to `cosf'
scene.c:(.text+0x252): undefined reference to `sinf'
scene.c:(.text+0x31b): undefined reference to `glGenBuffers'
scene.c:(.text+0x332): undefined reference to `glBindBuffer'
scene.c:(.text+0x358): undefined reference to `glBufferData'
scene.c:(.text+0x36e): undefined reference to `glEnableClientState'
scene.c:(.text+0x378): undefined reference to `glEnableClientState'
scene.c:(.text+0x394): undefined reference to `glVertexPointer'
scene.c:(.text+0x3ab): undefined reference to `glNormalPointer'
scene.o: In function `sceneInit':
scene.c:(.text+0x3c4): undefined reference to `glCreateProgram'
scene.c:(.text+0x40a): undefined reference to `glLinkProgram'
scene.c:(.text+0x425): undefined reference to `glGetProgramiv'
scene.c:(.text+0x44b): undefined reference to `glGetProgramiv'
scene.c:(.text+0x479): undefined reference to `glGetProgramInfoLog'
scene.c:(.text+0x4b4): undefined reference to `glDeleteProgram'
scene.c:(.text+0x4d5): undefined reference to `glGetUniformLocation'
scene.c:(.text+0x4f2): undefined reference to `glGetUniformLocation'
scene.c:(.text+0x50f): undefined reference to `glGetUniformLocation'
scene.c:(.text+0x5c5): undefined reference to `glLoadIdentity'
scene.c:(.text+0x606): undefined reference to `glTranslatef'
scene.o: In function `sceneRender':
scene.c:(.text+0x61a): undefined reference to `glClear'
scene.c:(.text+0x62c): undefined reference to `glUseProgram'
scene.c:(.text+0x648): undefined reference to `glUniform3fv'
scene.c:(.text+0x664): undefined reference to `glUniform3fv'
scene.c:(.text+0x680): undefined reference to `glUniform3fv'
scene.c:(.text+0x697): undefined reference to `glDrawArrays'
scene.c:(.text+0x6a6): undefined reference to `glUseProgram'
scene.c:(.text+0x6b7): undefined reference to `glPushMatrix'
scene.c:(.text+0x710): undefined reference to `glTranslatef'
scene.c:(.text+0x731): undefined reference to `glColor3fv'
scene.c:(.text+0x753): undefined reference to `glutSolidSphere'
scene.c:(.text+0x758): undefined reference to `glPopMatrix'
scene.c:(.text+0x76b): undefined reference to `glutSwapBuffers'
scene.o: In function `sceneCycle':
scene.c:(.text+0x8c4): undefined reference to `cosf'
scene.c:(.text+0x8f1): undefined reference to `cosf'
scene.c:(.text+0x906): undefined reference to `sinf'
scene.c:(.text+0x933): undefined reference to `sinf'
scene.c:(.text+0x957): undefined reference to `glutPostRedisplay'
shader.o: In function `shaderCompileFromFile':
shader.c:(.text+0x213): undefined reference to `glCreateShader'
shader.c:(.text+0x241): undefined reference to `glShaderSource'
shader.c:(.text+0x250): undefined reference to `glCompileShader'
shader.c:(.text+0x274): undefined reference to `glGetShaderiv'
shader.c:(.text+0x297): undefined reference to `glGetShaderiv'
shader.c:(.text+0x2c2): undefined reference to `glGetShaderInfoLog'
shader.c:(.text+0x2fe): undefined reference to `glDeleteShader'
shader.o: In function `shaderAttachFromFile':
shader.c:(.text+0x34a): undefined reference to `glAttachShader'
shader.c:(.text+0x359): undefined reference to `glDeleteShader'
collect2: error: ld returned 1 exit status
I do have glut and mesa installed and have read on some of the other questions that you should chance something in the order of the makefile but how in this instance?
You need to put $(LDFLAGS) (libraries) after the (object) file names, like
$(CC) $(OBJS) -o glsl_lighting $(LDFLAGS)
As per the online gcc manual for linking options
[...] It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.
So, the object files, using the library functions, should appear before the libraries themselves.
I am trying to compile a simple example program that depends on a shared library (so) that depends on liblua51.so. My source file is example.c and here is the command I am using to compile it (it is written in C)
cc -Wall -fPIC -ldl -o a.out -I./ste-linux/ste-interface-files/c/ -L./ste-linux/ste-shared-libraries/ example.c -lm -llua51 -lste -lm -ldl
I am getting the following errors:
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `sinh'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `ceil'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `atan2'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `tanh'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `cosh'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `fmod'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `acos'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `sin'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `atan'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `asin'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `exp'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `tan'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `cos'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `log'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `pow'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `log10'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `sqrt'
./ste-linux/ste-shared-libraries//liblua51.so: undefined reference to `floor'
I have read a bunch of other threads on stackoverflow saying adding the -lm flag will fix this, but no matter where I put the -L and -lm -ldl in the command, these undefined references will not go away.
I am trying to compile this lib on ubuntu 12.04 LTS
Help please
The issue was the shared library I was using was built with a different version of GCC. After I downgrade from Ubuntu 11.04 (from 12.04 LTS) it was resolved.