I'm trying to compile a program, but I get the following error when I run make install.
gcc -fPIC -O3 -g -O2 -o treeviewer -L/usr/include -lm -lpng -ljpeg -lgd treeviewer.o tree.o fileio.o tree.o:
In function `drawImage':
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:587: undefined reference to `gdFontMediumBold'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:587: undefined reference to `gdImageString'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:602: undefined reference to `gdImageLine'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:610: undefined reference to `gdImageLine'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:620: undefined reference to `gdImageFilledRectangle'
tree.o: In function `TreeToImage':
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:477: undefined reference to `gdFontMediumBold'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:526: undefined reference to `gdImageCreate'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:527: undefined reference to `gdImageColorAllocate'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:528: undefined reference to `gdImageColorAllocate'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:529: undefined reference to `gdImageColorAllocate'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:530: undefined reference to `gdImageColorAllocate'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:531: undefined reference to `gdImageColorAllocate'
tree.o:/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:532: more undefined references to `gdImageColorAllocate' follow
tree.o: In function `TreeToImage':
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:548: undefined reference to `gdImagePng'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:552: undefined reference to `gdImageDestroy'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:543: undefined reference to `gdImageJpeg'
tree.o: In function `printTreeInfo':
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:642: undefined reference to `gdFontMediumBold'
tree.o: In function `drawImage':
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:627: undefined reference to `gdImageRectangle'
/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:624: undefined reference to `gdImageFilledRectangle'
collect2: error: ld returned 1 exit status
make: *** [treeviewer] Error 1
I have installed the libgd using the commmand sudo apt-get -y install libgd2-xpm-dev build-essential. The folder /usr/include has the file gd.h. Could anyone tell me what am I missing? Thanks in advance.
You might need to list the directory where libgd.a is located with -L if it's not in the default directory list for gcc.
Solved it by changing
gcc -fPIC -O3 -g -O2 -o treeviewer -L/usr/include -lm -lpng -ljpeg -lgd treeviewer.o tree.o fileio.o tree.o
to
gcc -fPIC -O3 -g -O2 treeviewer.o tree.o fileio.o tree.o -L/usr/include -lm -lpng -ljpeg -lgd -o treeviewer
Related
I have a smal testing program to test ldap. I tried to compile it on Ubuntu 19.04. I have the source file called myldaptest.c, I ran:
1.gcc -c myldaptest.c
2.gcc -L/usr/lib/x86_64-linux-gnu -lldap -llber -o myldaptest myldaptest.o
then the it complains:
/usr/bin/ld: ldapsearch-sync.o: in function main':
ldapsearch-sync.c:(.text.startup+0x236): undefined reference toldap_url_parse'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x30b): undefined reference to ldap_initialize'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x33a): undefined reference toldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x374): undefined reference to ldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x3a3): undefined reference toldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x3ea): undefined reference to ldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x422): undefined reference toldap_set_option'
...
collect2: error: ld returned 1 exit status
who can tell me why?
I am working with this code i found on github.
In order to use the uspi library,the help documentation(USING SECTION) said that i should create a makefile and specify the includes and libraries files there.
Because i am new to makefile concept,i first try to manually do that by typing:
arm-linux-gnueabihf-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -std=c99 -I./uspi/env/include -I./uspi/include -L./uspi/lib -luspi w.o -o kernel.elf
this errors comes up:
w.o: In function `main':
w.c:(.text+0xc): undefined reference to `USPiEnvInitialize'
w.c:(.text+0x24): undefined reference to `USPiInitialize'
w.c:(.text+0x48): undefined reference to `LogWrite'
w.c:(.text+0x4c): undefined reference to `USPiEnvClose'
w.c:(.text+0x58): undefined reference to `USPiMassStorageDeviceAvailable'
w.c:(.text+0x80): undefined reference to `LogWrite'
w.c:(.text+0x84): undefined reference to `USPiEnvClose'
w.c:(.text+0xb8): undefined reference to `USPiMassStorageDeviceRead'
w.c:(.text+0xdc): undefined reference to `LogWrite'
w.c:(.text+0x108): undefined reference to `LogWrite'
w.c:(.text+0x124): undefined reference to `LogWrite'
w.c:(.text+0x13c): undefined reference to `LogWrite'
w.c:(.text+0x204): undefined reference to `LogWrite'
w.c:(.text+0x23c): undefined reference to `USPiEnvClose'
collect2: error: ld returned 1 exit status
i need the .elf file so i can generate a .img file from it
This link order:
arm-linux-gnueabihf-gcc ... -luspi w.o -o kernel.elf
is incorrect. Libraries should follow the objects they are referenced from:
arm-linux-gnueabihf-gcc ... w.o -luspi -o kernel.elf
Explanation.
I am trying to built some sample gtk+ examples that came with the gtk+ sources. My need was only to have a gtk+ UI to a C program. I went about downloading and building gtk+ but realised (through SO) that this was not needed and that I only need libgtk-3-dev.
sudo apt-get install libgtk-3-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libgtk-3-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 373 not upgraded.
EDIT: NOTE: Issue is not with the sequence of libraries or includes as I am using the makefile that came with gtk+.
I tried compiling an example that I had with the gtk+ code I downloaded. I get the below errors. The other queries on this topic mentioned that the order of the flags matter, but in this case I have used the makefile that came with the sources. Should I be installing something more than the libgtk-3-dev library (running on Ubuntu 14.04 ).
~/gtk/examples/application1$ make -f Makefile.example
cc -c -o main.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 main.c
cc -c -o exampleapp.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 exampleapp.c
cc -c -o exampleappwin.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 exampleappwin.c
cc -o exampleapp -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 main.o exampleapp.o exampleappwin.o
main.o: In function main':
main.c:(.text+0x11): undefined reference tog_application_get_type'
main.c:(.text+0x24): undefined reference to g_type_check_instance_cast'
main.c:(.text+0x35): undefined reference tog_application_run'
exampleapp.o: In function example_app_class_intern_init':
exampleapp.c:(.text+0x14): undefined reference tog_type_class_peek_parent'
exampleapp.c:(.text+0x36): undefined reference to g_type_class_adjust_private_offset'
exampleapp.o: In functionexample_app_get_type':
exampleapp.c:(.text+0x66): undefined reference to g_once_init_enter'
exampleapp.c:(.text+0x84): undefined reference tog_intern_static_string'
exampleapp.c:(.text+0x8c): undefined reference to gtk_application_get_type'
exampleapp.c:(.text+0xb4): undefined reference tog_type_register_static_simple'
exampleapp.c:(.text+0xc9): undefined reference to g_once_init_leave'
exampleapp.o: In functionexample_app_activate':
exampleapp.c:(.text+0x104): undefined reference to g_type_check_instance_cast'
exampleapp.c:(.text+0x115): undefined reference togtk_window_get_type'
exampleapp.c:(.text+0x127): undefined reference to g_type_check_instance_cast'
exampleapp.c:(.text+0x12f): undefined reference togtk_window_present'
exampleapp.o: In function example_app_open':
exampleapp.c:(.text+0x14d): undefined reference togtk_application_get_type'
exampleapp.c:(.text+0x15f): undefined reference to g_type_check_instance_cast'
exampleapp.c:(.text+0x167): undefined reference togtk_application_get_windows'
exampleapp.c:(.text+0x18c): undefined reference to g_type_check_instance_cast'
exampleapp.c:(.text+0x1a9): undefined reference tog_type_check_instance_cast'
exampleapp.c:(.text+0x1f5): undefined reference to gtk_window_get_type'
exampleapp.c:(.text+0x207): undefined reference tog_type_check_instance_cast'
exampleapp.c:(.text+0x20f): undefined reference to gtk_window_present'
exampleapp.o: In functionexample_app_class_init':
exampleapp.c:(.text+0x222): undefined reference to g_application_get_type'
exampleapp.c:(.text+0x234): undefined reference tog_type_check_class_cast'
exampleapp.c:(.text+0x244): undefined reference to g_application_get_type'
exampleapp.c:(.text+0x256): undefined reference tog_type_check_class_cast'
exampleapp.o: In function example_app_new':
exampleapp.c:(.text+0x294): undefined reference tog_object_new'
exampleappwin.o: In function example_app_window_class_intern_init':
exampleappwin.c:(.text+0x14): undefined reference tog_type_class_peek_parent'
exampleappwin.c:(.text+0x36): undefined reference to g_type_class_adjust_private_offset'
exampleappwin.o: In functionexample_app_window_get_type':
exampleappwin.c:(.text+0x66): undefined reference to g_once_init_enter'
exampleappwin.c:(.text+0x84): undefined reference tog_intern_static_string'
exampleappwin.c:(.text+0x8c): undefined reference to gtk_application_window_get_type'
exampleappwin.c:(.text+0xb4): undefined reference tog_type_register_static_simple'
exampleappwin.c:(.text+0xc9): undefined reference to g_once_init_leave'
exampleappwin.o: In functionexample_app_window_new':
exampleappwin.c:(.text+0x117): undefined reference to `g_object_new'
collect2: error: ld returned 1 exit status
make: *** [exampleapp] Error 1
For whatever reason the Makefile in the GTK+ 3.20 source tree is broken; as per n.m.'s comment. There might already be a bugfix, if not a fix, for that.
But you can't use GTK+ 3.20 with the GTK+ 3.10 that comes with Ubuntu 14.04 LTS. You're better off using the GTK+ 3.10 examples and source code. If you really want to use a newer version of GTK+, you can use jhbuild to set up an environment separate from the rest of the system (typically in /opt/gnome) to build a newer versions of GTK+ into.
I'm trying to compile a program called Contrafold and I need two libraries (libgd and libpng), the problem is a link the libraries but it through me an undefined reference error, I don't know why....My code to compile is the follow:
g++ -O3 -DNDEBUG -W -pipe -Wundef -Winline --param large-function-growth=100000 -Wall EncapsulatedPostScript.o PlotRNA.o SStruct.o Utilities.o -o plot_rna -lm -L/path-to-library/libgd.a -L/path-to-library/libpng16.a
and the errors are:
PlotRNA.cpp:(.text+0x189e): undefined reference to `gdImageString'
PlotRNA.cpp:(.text+0x1a34): undefined reference to `gdImageFilledArc'
PlotRNA.cpp:(.text+0x1a79): undefined reference to `gdImageSetAntiAliased'
PlotRNA.cpp:(.text+0x1ad6): undefined reference to `gdImageChar'
PlotRNA.cpp:(.text+0x1c76): undefined reference to `gdImageLine'
PlotRNA.cpp:(.text+0x1fce): undefined reference to `gdImageString'
PlotRNA.cpp:(.text+0x2036): undefined reference to `gdImageCreateTrueColor'
PlotRNA.cpp:(.text+0x2079): undefined reference to `gdImageColorAllocate'
PlotRNA.cpp:(.text+0x2093): undefined reference to `gdImageColorAllocate'
PlotRNA.cpp:(.text+0x213a): undefined reference to `gdImageColorAllocate'
PlotRNA.cpp:(.text+0x217d): undefined reference to `gdImageFilledRectangle'
PlotRNA.cpp:(.text+0x2182): undefined reference to `gdFontGetMediumBold'
PlotRNA.cpp:(.text+0x218f): undefined reference to `gdFontGetSmall'
PlotRNA.cpp:(.text+0x223b): undefined reference to `gdImagePng'
PlotRNA.cpp:(.text+0x2250): undefined reference to `gdImageDestroy'
Any options?
Probably you forgot to add linking with library containing gd* functions: -lgd
I would understand this error message if I had not put the -lboost_system flag, but it is really here:
g++ -o build/myproject build/main/main.o -L/usr/local/boost/boost_1_52_0/boost/libs -L/usr/lib -Lbuild -L. -lboost_system -lboost_thread -lpthread -lboost_regex -lpq -lmylibrary
build/libmylibrary.a(library.o): In function `__static_initialization_and_destruction_0(int, int)':
library.cpp:(.text+0x25f): undefined reference to `boost::system::generic_category()'
library.cpp:(.text+0x269): undefined reference to `boost::system::generic_category()'
library.cpp:(.text+0x273): undefined reference to `boost::system::system_category()'
Do you have any idea what should I investigate to solve the problem ? (I use gcc 4.6.3)
The order at which you link your libraries matters, in your case you have library.cpp that apparently uses the boost_system library
library.cpp:(.text+0x25f): undefined reference to `boost::system::generic_category()'
library.cpp:(.text+0x269): undefined reference to `boost::system::generic_category()'
library.cpp:(.text+0x273): undefined reference to `boost::system::system_category()'
To solve this you should move the boost_system library to the end of your link line
g++ -o build/myproject build/main/main.o -L/usr/local/boost/boost_1_52_0/boost/libs -L/usr/lib -Lbuild -L. -lboost_thread -lpthread -lboost_regex -lpq -lmylibrary **-lboost_system**
Alternatively, build libmylibrary.so as a shared library and link to the boost_system library directly.