pwntcha build error in Cygwin: undefined reference to imlib_load_image - cygwin

I'm trying to build pwntcha on windows using Cygwin with imlib2. At the "make" step I get the error message:
/home/username/pwntcha/src/image.c:37: undefined reference to imlib_load_image.
Can anyone help me to solve it?
For more detailed:
gcc `imlib2-config --cflags` -DX_DISPLAY_MISSING=1 -Wall -O6 -g -O2 `imlib2-config --libs` -o pwntcha.exe pwntcha-main.o pwntcha-filter.o pwntcha-font.o pwntcha-image.o pwntcha-easter-eggs.o pwntcha-test.o authimage/libdecoder.a clubic/libdecoder.a java/libdecoder.a linuxfr/libdecoder.a livejournal/libdecoder.a lmt/libdecoder.a paypal/libdecoder.a phpbb/libdecoder.a scode/libdecoder.a slashdot/libdecoder.a ticketmaster/libdecoder.a tickets/libdecoder.a vbulletin/libdecoder.a xanga/libdecoder.a
pwntcha-image.o: In function `image_load':
/home/username/pwntcha/src/image.c:37: undefined reference to "imlib_load_image"
/home/username/pwntcha/src/image.c:63: undefined reference to "imlib_context_set_image"
/home/username/pwntcha/src/image.c:64: undefined reference to "imlib_image_get_width"
/home/username/pwntcha/src/image.c:65: undefined reference to "imlib_image_get_height"
/home/username/pwntcha/src/image.c:66: undefined reference to "imlib_image_get_width"
/home/username/pwntcha/src/image.c:68: undefined reference to "imlib_image_get_data"
Thank in advance.

gcc resolves symbols in the order listed. You need to patch the build system to move `imlib2-config --libs` to the very end of the link command.

Related

Linux Fedora swift symbol lookup error

I'm trying to get swift working on my Fedora 22. I've followed the official instructions (https://swift.org/getting-started/#installing-swift).
I'm able to use the swift REPL and execute a swift file without compiling it with swift main.swift
swift.main content:
print("Hello, world!")
When I'm trying to compile it via:
swiftc main.swift -o main
I'm getting the following error:
[christian#roodrallec Sources]$ swiftc main.swift -o main -v
Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c)
Target: x86_64-unknown-linux-gnu
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/bin/swift -frontend -c -primary-file main.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name main -o /tmp/main-dd738b.o
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/bin/swift-autolink-extract /tmp/main-dd738b.o -o /tmp/main-739e5f.autolink
/usr/bin/clang++ /tmp/main-dd738b.o -L /home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux -Xlinker -rpath -Xlinker /home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux -lswiftCore #/tmp/main-739e5f.autolink -Xlinker -T /home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/x86_64/swift.ld -o main
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `uiter_setUTF8_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `ucol_strcollIter_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `uiter_setString_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `ucol_next_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `ucol_closeElements_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `u_strToUpper_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `ucol_strcoll_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `ucol_open_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `u_strToLower_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `ucol_openElements_55'
/home/christian/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/lib/swift/linux/libswiftCore.so: undefined reference to `ucol_setAttribute_55'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
Is it, because the binaries are for Ubuntu? Or what did i miss?
Thanks in advance!
As you probably know, the errors indicate that there are some symbols, most likely functions, that are needed by Swift, but are not available in any of the libraries that are being used. The function names aren't ringing the bell with me, so I cannot really tell how to resolve these particular errors.
I think at this point you might want to try building Swift from source as described here: https://github.com/apple/swift/blob/master/README.md. Using Ubuntu binaries on Fedora is probably not a good idea. Even if you get past these errors, something else is likely to come up later.
I haven't tried building Swift from source yet, so can't really share any experiences on that.

Linking with libbluetooth.so

On Ubuntu 14.04, I'm trying to do a small example of bluetooth device listing but I'm facing a simple issue about linking with the bluetooth shared library when compiling this minimalistic demo http://people.csail.mit.edu/albert/bluez-intro/c404.html:
$ sudo apt-get install libbluetooth-dev
$ gcc -lbluetooth simplescan.c -o simplescan
/tmp/ccuwRsB5.o: In function `main':
simplescan.c:(.text+0x79): undefined reference to `hci_get_route'
simplescan.c:(.text+0x8c): undefined reference to `hci_open_dev'
simplescan.c:(.text+0x132): undefined reference to `hci_inquiry'
simplescan.c:(.text+0x18f): undefined reference to `ba2str'
simplescan.c:(.text+0x1f0): undefined reference to `hci_read_remote_name'
collect2: error: ld returned 1 exit status
$ nm -D /usr/lib/x86_64-linux-gnu/libbluetooth.so.3.13.0 | grep hci_get_route
0000000000008f00 T hci_get_route
The bluetooth shared library seems to be found and containing the required functions, but the linking phase doesn't achieve.
The solution is astonished (to me): the order of the arguments given to gcc is important. "-lbluetooth" should be put after "simplescan.c":
$ gcc simplescan.c -lbluetooth -o simplescan # Success
$ gcc -lbluetooth simplescan.c -o simplescan # Failure
/tmp/ccWhZFXs.o: In function `main':
simplescan.c:(.text+0x79): undefined reference to `hci_get_route'
simplescan.c:(.text+0x8c): undefined reference to `hci_open_dev'
simplescan.c:(.text+0x132): undefined reference to `hci_inquiry'
simplescan.c:(.text+0x18f): undefined reference to `ba2str'
simplescan.c:(.text+0x1f0): undefined reference to `hci_read_remote_name'
collect2: error: ld returned 1 exit status

Undefined reference to WinMain in Cygwin

I am trying to compile and having following problem
$ gcc errlib.c -o errlib.o
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../lib/libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.30-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain'
/usr/src/debug/cygwin-1.7.30-1/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status
Any suggestions? These files are well tested and generated the code fine before but now i think there might be some cygwin settings or so ... m compiling on windows 8 on cygwin.
Use -c compile flag to only produce object file. Without -c it tries to link an executable and the linker (called automatically) fails.

Undefine reference for libraries, so How could I find the right path?

I am trying to compile a v4l2 example in Ubuntu but I am getting the following error:
guilherme#notedev01:~/Downloads/V4l2_samples-0.4.1$ make
gcc -O2 -L/usr/include -lX11 -lXext -o viewer viewer.c
/tmp/ccUjnjWQ.o: In function `image_destroy':
viewer.c:(.text+0x234): undefined reference to `XDestroyImage'
viewer.c:(.text+0x256): undefined reference to `XFreeGC'
viewer.c:(.text+0x277): undefined reference to `XShmDetach'
viewer.c:(.text+0x2ac): undefined reference to `XFreePixmap'
/tmp/ccUjnjWQ.o: In function `image_create':
viewer.c:(.text+0x305): undefined reference to `XCreateGC'
viewer.c:(.text+0x31d): undefined reference to `XGetWindowAttributes'
viewer.c:(.text+0x39e): undefined reference to `XShmCreateImage'
viewer.c:(.text+0x3f5): undefined reference to `XShmAttach'
viewer.c:(.text+0x44e): undefined reference to `XCreateImage'
viewer.c:(.text+0x494): undefined reference to `XShmQueryExtension'
viewer.c:(.text+0x4b4): undefined reference to `XShmPixmapFormat'
viewer.c:(.text+0x4dc): undefined reference to `XShmCreatePixmap'
/tmp/ccUjnjWQ.o: In function `image_put':
viewer.c:(.text+0x54c): undefined reference to `XPutImage'
viewer.c:(.text+0x586): undefined reference to `XShmPutImage'
/tmp/ccUjnjWQ.o: In function `main':
viewer.c:(.text.startup+0x18b): undefined reference to `XOpenDisplay'
viewer.c:(.text.startup+0x1b1): undefined reference to `XScreenOfDisplay'
viewer.c:(.text.startup+0x1ee): undefined reference to `XCreateSimpleWindow'
viewer.c:(.text.startup+0x249): undefined reference to `XMapRaised'
viewer.c:(.text.startup+0x263): undefined reference to `XStoreName'
viewer.c:(.text.startup+0x280): undefined reference to `XGetWindowAttributes'
viewer.c:(.text.startup+0x92f): undefined reference to `XPending'
viewer.c:(.text.startup+0x94c): undefined reference to `XNextEvent'
viewer.c:(.text.startup+0xaee): undefined reference to `XPending'
viewer.c:(.text.startup+0xb0b): undefined reference to `XNextEvent'
viewer.c:(.text.startup+0xf39): undefined reference to `XPending'
viewer.c:(.text.startup+0xf56): undefined reference to `XNextEvent'
collect2: error: ld returned 1 exit status
make: *** [viewer] Error 1
What I can see is that the path for -lx11 and -lXext isn't -L/usr/include.
How can I find the right path for those libraries?
Thanks.
as Chris has pointed out, the order is wrong, you need to put the -lX11 -lXext after the source-code/object-files.
this is because modern compilers try to optimize the final result and not link against unused libraries.
they do so by maintaining a list of unresolved symbols within an object and use any binary files that come aferwards in the linker arguments to resolve those symbols.
example
your program test uses the function do_foo() from libfoo and the function do_bar_do() from libbar.
you link it using:
$ gcc -o test test.o -lfoo -lbar
the linker first searches test.o and notices that some symbols (do_foo and do_bar_do) are not defined anywhere. it then proceeds to libfoo (specified right after test.o) and finds that it provides do_foo, so it creates code to use it from your program. do_bar_do is still unresolved, until the linker checks upon libbar.
consider doing it the wrong way:
$ gcc -o test -lfoo test.o -lbar
the linker will first check libfoo and see that it doesn't contain any unresolved symbols. cool. it will then proceed to test.o and notice do_bar_do and do_foo. do_bar_do is resolved by the right-hand libbar but do_foo is not resolved at all, and you get an error:
undefined reference to `do_foo'
"but the code is meant to be a tutorial..."
so why is it not working?
older compilers where a bit lax about the order of dependencies (they would check all binaries/libraries/objects whether a given symbol could be resolved); that's why you can still find code out there that puts the libraries to link against before the object files.
The -lX11 -lXext must come after the viewer.c in the command line (and should probably be in the order -lXext -lX11). Also, ensure that the libx11-6-dev and libxext6-dev packages are installed.
System libraries are usually in /lib and /usr/lib, and you do not need to use -L to specify those directories.

undefined reference to `jack_client_close`, et al

I'm trying to follow this introductory tutorial on jack (audio server for linux). In the tutorial, the author explains that you should use pkg-config to find the cflags and libs for jack, making the gcc command like this:
gcc -o simple_client `pkg-config --cflags --libs jack` simple_client.c
which gives the output:
/tmp/ccyuOC0u.o: In function `signal_handler':
simple_client.c:(.text+0x16): undefined reference to `jack_client_close'
/tmp/ccyuOC0u.o: In function `process':
simple_client.c:(.text+0x6f): undefined reference to `jack_port_get_buffer'
simple_client.c:(.text+0x87): undefined reference to `jack_port_get_buffer'
/tmp/ccyuOC0u.o: In function `main':
simple_client.c:(.text+0x25b): undefined reference to `sin'
simple_client.c:(.text+0x2c1): undefined reference to `jack_client_open'
simple_client.c:(.text+0x372): undefined reference to `jack_get_client_name'
simple_client.c:(.text+0x3b1): undefined reference to `jack_set_process_callback'
simple_client.c:(.text+0x3ca): undefined reference to `jack_on_shutdown'
simple_client.c:(.text+0x3ee): undefined reference to `jack_port_register'
simple_client.c:(.text+0x419): undefined reference to `jack_port_register'
simple_client.c:(.text+0x475): undefined reference to `jack_activate'
simple_client.c:(.text+0x4c5): undefined reference to `jack_get_ports'
simple_client.c:(.text+0x514): undefined reference to `jack_port_name'
simple_client.c:(.text+0x52c): undefined reference to `jack_connect'
simple_client.c:(.text+0x56e): undefined reference to `jack_port_name'
simple_client.c:(.text+0x586): undefined reference to `jack_connect'
simple_client.c:(.text+0x5ba): undefined reference to `jack_free'
collect2: ld returned 1 exit status
I'm not very experienced using gcc or writing c programs generally (most of my experience has been with javascript, clojure, java, python, and php). What I gather from this and my research into it is that some libraries are missing or linked incorrectly (not sure which).
So just running pkg-config --cflags --libs jack on my machine, I get:
-ljack
In the tutorial referenced above, the author demonstrates the same method for gleaning the libs to be linked for jack, but his output looks like this:
-ljack -lpthread -ldl -lrt
Not sure what pthread is, but I think dl is dsp-loader, and rt has something to do with realtime. I've searched in several directories called /lib and haven't come across anything for these other libs, so I don't think they exist on my machine. However, it seems strange to me that calling pkg-config doesn't make any mention of them. How should I go about finding these libs? Or am I on the wrong track?
Your link command line is wrong, try this one instead:
gcc -o simple_client simple_client.c `pkg-config --cflags --libs jack`
The order of archive libraries on command line matters.

Resources