undefined references when building xulrunner - linker

I'm trying to build xulrunner version 2.0 (sources downloaded from mozilla ftp site) but I keep getting some undefined references when trying to create libxul.so. I tried version 10.0 but same results.
I'm building on Archlinux, but I also get the same error on Ubuntu from the VM I downloaded from mozilla site.
Prior to build xulrunner, some modifications were required in order to build:
https://hg.mozilla.org/mozilla-central/rev/effb4811409b
https://hg.mozilla.org/mozilla-central/rev/87a5ed480992
needed to create an empty /usr/include/curl/types.h file
file security/coreconf/Linux3.16.mk does not exist : copy Linux2.6.mk to Linux3.16.mk
The .mozconfig I'm using:
mk_add_options AUTOCONF=autoconf-2.13
mk_add_options PYTHON=/usr/bin/python2
mk_add_options MOZ_CO_PROJECT=xulrunner
mk_add_options MOZ_OBJDIR=#topsrcdir#/obj-xulrunner
ac_add_options --enable-application=xulrunner
ac_add_options --disable-javaxpcom
After about 30 minutes, I get these errors when trying to build libxul.so:
...
rm -f libxul.so
c++ -fno-rtti -fno-exceptions -Wall -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-invalid-offsetof -Wno-variadic-macros -Werror=return-type -pedantic -Wno-long-long -fno-strict-aliasing -fshort-wchar -pthread -pipe -DNDEBUG -DTRIMMED -Os -freorder-blocks -fomit-frame-pointer -fPIC -shared -Wl,-z,defs -Wl,-h,libxul.so -o libxul.so nsStaticXULComponents.o nsUnicharUtils.o nsBidiUtils.o nsRDFResource.o -lpthread -Wl,-rpath-link,/disk2/mozilla/buildtmp/obj-xulrunner/dist/bin -Wl,-rpath-link,/usr/local/lib -Wl,--whole-archive ../../embedding/browser/gtk/src/libgtkembedmoz.a ../../toolkit/xre/libxulapp_s.a ../../staticlib/components/libnecko.a ../../staticlib/components/libuconv.a ../../staticlib/components/libi18n.a ../../staticlib/components/libchardet.a ../../staticlib/components/libjar50.a ../../staticlib/components/libstartupcache.a ../../staticlib/components/libpref.a ../../staticlib/components/libhtmlpars.a ../../staticlib/components/libimglib2.a ../../staticlib/components/libgklayout.a ../../staticlib/components/libdocshell.a ../../staticlib/components/libembedcomponents.a ../../staticlib/components/libwebbrwsr.a ../../staticlib/components/libnsappshell.a ../../staticlib/components/libtxmgr.a ../../staticlib/components/libcommandlines.a ../../staticlib/components/libtoolkitcomps.a ../../staticlib/components/libpipboot.a ../../staticlib/components/libpipnss.a ../../staticlib/components/libappcomps.a ../../staticlib/components/libjetpack_s.a ../../staticlib/components/libjsctypes.a ../../staticlib/components/libjsperf.a ../../staticlib/components/libgkplugin.a ../../staticlib/components/libunixproxy.a ../../staticlib/components/libjsd.a ../../staticlib/components/libautoconfig.a ../../staticlib/components/libauth.a ../../staticlib/components/libcookie.a ../../staticlib/components/libpermissions.a ../../staticlib/components/libuniversalchardet.a ../../staticlib/components/libcomposer.a ../../staticlib/components/librdf.a ../../staticlib/components/libwindowds.a ../../staticlib/components/libfileview.a ../../staticlib/components/libstoragecomps.a ../../staticlib/components/libplaces.a ../../staticlib/components/libtkautocomplete.a ../../staticlib/components/libsatchel.a ../../staticlib/components/libpippki.a ../../staticlib/components/libwidget_gtk2.a ../../staticlib/components/libsystem-pref.a ../../staticlib/components/libimgicon.a ../../staticlib/components/libgkgfxthebes.a ../../staticlib/components/libaccessibility.a ../../staticlib/components/libremoteservice.a ../../staticlib/components/libspellchecker.a ../../staticlib/components/libzipwriter.a ../../staticlib/components/libservices-crypto.a ../../staticlib/libjsipc_s.a ../../staticlib/libdomipc_s.a ../../staticlib/libdomplugins_s.a ../../staticlib/libmozipc_s.a ../../staticlib/libmozipdlgen_s.a ../../staticlib/libipcshell_s.a ../../staticlib/libgfxipc_s.a ../../staticlib/libxpcom_core.a ../../staticlib/libucvutil_s.a ../../staticlib/libgkgfx.a ../../staticlib/libchromium_s.a ../../staticlib/libmozreg_s.a ../../staticlib/libmorkreader_s.a ../../staticlib/libgtkxtbin.a ../../staticlib/libthebes.a ../../staticlib/libycbcr.a ../../staticlib/libangle.a -Wl,--no-whole-archive -L../../dist/lib -lmozsqlite3 -L../../dist/bin -L../../dist/lib -L../../jpeg -lmozjpeg -L../../modules/libimg/png -lmozpng -L../../gfx/qcms -lmozqcms -L/disk2/mozilla/buildtmp/obj-xulrunner/dist/bin -ljs_static -L../../dist/bin -L../../dist/lib -lcrmf -lsmime3 -lssl3 -lnss3 -lnssutil3 -L../../gfx/cairo/cairo/src -lmozcairo -L../../gfx/cairo/libpixman/src -lmozlibpixman -lXrender -lfreetype -lfontconfig ../../gfx/harfbuzz/src/libmozharfbuzz.a ../../gfx/ots/src/libmozots.a -L../../modules/zlib/src -lmozz -lasound -lrt -L../../dist/bin -L../../dist/lib -L/disk2/mozilla/buildtmp/obj-xulrunner/dist/lib -lplds4 -lplc4 -lnspr4 -lpthread -ldl -L../../dist/lib -lmozalloc -ldbus-1 -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0 -lX11 -lXext -lpangoft2-1.0 -lfontconfig -lfreetype -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lcairo -lgtk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lfontconfig -lfreetype -lgdk-x11-2.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lXt -lgthread-2.0 -lfreetype -lz -lbz2 -lpng16 -lharfbuzz -ldl -lrt
../../staticlib/libthebes.a(gfxPangoFonts.o): In function `gfxDownloadedFcFontEntry::~gfxDownloadedFcFontEntry()':
gfxPangoFonts.cpp:(.text+0x1a63): undefined reference to `FT_Done_Face'
../../staticlib/libthebes.a(gfxPangoFonts.o): In function `gfxPangoFontGroup::NewFontEntry(gfxProxyFontEntry const&, unsigned char const*, unsigned int)':
gfxPangoFonts.cpp:(.text+0x3a61): undefined reference to `FT_New_Memory_Face'
../../staticlib/libthebes.a(gfxFT2Utils.o): In function `gfxFT2LockedFace::GetGlyph(unsigned int)':
gfxFT2Utils.cpp:(.text+0x6b): undefined reference to `FT_Select_Charmap'
../../staticlib/libthebes.a(gfxFT2Utils.o): In function `gfxFT2LockedFace::GetMetrics(gfxFont::Metrics*, unsigned int*)':
gfxFT2Utils.cpp:(.text+0x216): undefined reference to `FT_Get_Sfnt_Table'
gfxFT2Utils.cpp:(.text+0x450): undefined reference to `FT_Get_Sfnt_Table'
../../staticlib/libthebes.a(gfxFT2Utils.o): In function `gfxFT2LockedFace::FindCharVariantFunction()':
gfxFT2Utils.cpp:(.text+0x78e): undefined reference to `FT_Library_Version'
../../staticlib/libthebes.a(gfxFT2Utils.o): In function `gfxFT2LockedFace::GetUVSGlyph(unsigned int, unsigned int)':
gfxFT2Utils.cpp:(.text+0x84c): undefined reference to `FT_Select_Charmap'
../../staticlib/libthebes.a(gfxFT2Utils.o): In function `gfxFT2LockedFace::GetFontTable(unsigned int, FallibleTArray<unsigned char>&)':
gfxFT2Utils.cpp:(.text+0x8ba): undefined reference to `FT_Load_Sfnt_Table'
gfxFT2Utils.cpp:(.text+0x951): undefined reference to `FT_Load_Sfnt_Table'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_unscaled_font_map_lock':
cairo-ft-font.c:(.text+0x7c): undefined reference to `FT_Init_FreeType'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_unscaled_font_set_scale':
cairo-ft-font.c:(.text+0x347): undefined reference to `FT_Set_Transform'
cairo-ft-font.c:(.text+0x3af): undefined reference to `FT_Set_Char_Size'
cairo-ft-font.c:(.text+0x445): undefined reference to `FT_Set_Char_Size'
cairo-ft-font.c:(.text+0x462): undefined reference to `FT_Set_Pixel_Sizes'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_scaled_glyph_vertical_layout_bearing_fix':
cairo-ft-font.c:(.text+0xa25): undefined reference to `FT_Vector_Transform'
cairo-ft-font.c:(.text+0xa3a): undefined reference to `FT_Outline_Translate'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_unscaled_font_map_pluck_entry':
cairo-ft-font.c:(.text+0x11e9): undefined reference to `FT_Done_Face'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_unscaled_font_destroy':
cairo-ft-font.c:(.text+0x16ba): undefined reference to `FT_Done_Face'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_unscaled_font_lock_face':
cairo-ft-font.c:(.text+0x1aee): undefined reference to `FT_New_Face'
cairo-ft-font.c:(.text+0x1b11): undefined reference to `FT_Done_Face'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_index_to_ucs4':
cairo-ft-font.c:(.text+0x1b8c): undefined reference to `FT_Get_First_Char'
cairo-ft-font.c:(.text+0x1baf): undefined reference to `FT_Get_Next_Char'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_scaled_glyph_init':
cairo-ft-font.c:(.text+0x1ce6): undefined reference to `FT_Load_Glyph'
cairo-ft-font.c:(.text+0x1e9a): undefined reference to `FT_Outline_Transform'
cairo-ft-font.c:(.text+0x1eac): undefined reference to `FT_Outline_Decompose'
cairo-ft-font.c:(.text+0x2012): undefined reference to `FT_Render_Glyph'
cairo-ft-font.c:(.text+0x20ac): undefined reference to `FT_Load_Glyph'
cairo-ft-font.c:(.text+0x2114): undefined reference to `FT_GlyphSlot_Embolden'
cairo-ft-font.c:(.text+0x21f3): undefined reference to `FT_Outline_Get_CBox'
cairo-ft-font.c:(.text+0x291e): undefined reference to `FT_Outline_Transform'
cairo-ft-font.c:(.text+0x29b1): undefined reference to `FT_Outline_Translate'
cairo-ft-font.c:(.text+0x29d3): undefined reference to `FT_Outline_Get_Bitmap'
cairo-ft-font.c:(.text+0x2be4): undefined reference to `FT_GlyphSlot_Embolden'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_load_truetype_table':
cairo-ft-font.c:(.text+0x2d70): undefined reference to `FT_Load_Sfnt_Table'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-ft-font.o): In function `_cairo_ft_font_reset_static_data':
cairo-ft-font.c:(.text+0x358f): undefined reference to `FT_Done_FreeType'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-type1-subset.o): In function `cairo_type1_font_subset_get_glyph_names_and_widths':
cairo-type1-subset.c:(.text+0x379): undefined reference to `FT_Load_Glyph'
cairo-type1-subset.c:(.text+0x3b1): undefined reference to `FT_Get_Glyph_Name'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-type1-subset.o): In function `_cairo_type1_subset_init':
cairo-type1-subset.c:(.text+0xa8e): undefined reference to `FT_Get_PS_Font_Info'
../../gfx/cairo/cairo/src/libmozcairo.a(cairo-type1-subset.o): In function `_cairo_type1_scaled_font_is_type1':
cairo-type1-subset.c:(.text+0x1924): undefined reference to `FT_Get_PS_Font_Info'
/usr/bin/ld: libxul.so: hidden symbol `FT_Outline_Get_Bitmap' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
/disk2/mozilla/sources/10.0/mozilla-2.0/config/rules.mk:1291: recipe for target 'libxul.so' failed
make[4]: *** [libxul.so] Error 1
make[4]: Leaving directory '/disk2/mozilla/buildtmp/obj-xulrunner/toolkit/library'
/disk2/mozilla/sources/10.0/mozilla-2.0/config/rules.mk:783: recipe for target 'libs_tier_platform' failed
make[3]: *** [libs_tier_platform] Error 2
make[3]: Leaving directory '/disk2/mozilla/buildtmp/obj-xulrunner'
/disk2/mozilla/sources/10.0/mozilla-2.0/config/rules.mk:793: recipe for target 'tier_platform' failed
make[2]: *** [tier_platform] Error 2
make[2]: Leaving directory '/disk2/mozilla/buildtmp/obj-xulrunner'
/disk2/mozilla/sources/10.0/mozilla-2.0/config/rules.mk:746: recipe for target 'default' failed
make[1]: *** [default] Error 2
make[1]: Leaving directory '/disk2/mozilla/buildtmp/obj-xulrunner'
client.mk:345: recipe for target 'build' failed
make: *** [build] Error 2
The command line used to create libxul.so does contains the '-lfreetype', and when I look for FT_Done_Face function into libfreetype.so, it is present :
[dev400t#arch mozilla-2.0]$ nm --dynamic /usr/lib/libfreetype.so | grep FT_Done_Face
000000000001b300 T FT_Done_Face
I did add the "-Wl,-t" option to the command line to make sure libfreetype.so could be found: it is found.
What am I missing?

Your freetype2 version is >= 2.5.1. It contains this change http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=fae382076409db198dfbff36ac4cbb97b05b30a1, which is backwards-incompatible as far as Firefox is concerned.
You need to backport the fix from this bug to your source tree: https://bugzilla.mozilla.org/show_bug.cgi?id=944454 or downgrade your libfreetype2.
Firefox sources as of version 26 and later (including 24 ESR) already contain the fix.

Related

Makefile works on macos but doesn't on linux

I have a c program with a makefile that works perfectly on macos but when i try yo run it on linux it gives me a bunch of errors
gcc ./libft/libft.a srcs/main.o -o push_swap
/usr/bin/ld: srcs/main.o: in function `sa':
main.c:(.text+0x97): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `sb':
main.c:(.text+0x149): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `ss':
main.c:(.text+0x1eb): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `pa':
main.c:(.text+0x236): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `pb':
main.c:(.text+0x2df): undefined reference to `ft_putstr'
/usr/bin/ld: main.c:(.text+0x327): undefined reference to `ft_putnbr_fd'
/usr/bin/ld: srcs/main.o: in function `printstack':
main.c:(.text+0x3b3): undefined reference to `ft_putnbr_fd'
/usr/bin/ld: main.c:(.text+0x3bd): undefined reference to `ft_putchar'
/usr/bin/ld: main.c:(.text+0x3df): undefined reference to `ft_putnbr_fd'
/usr/bin/ld: main.c:(.text+0x3e9): undefined reference to `ft_putchar'
/usr/bin/ld: main.c:(.text+0x404): undefined reference to `ft_putstr'
/usr/bin/ld: main.c:(.text+0x413): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `main':
main.c:(.text+0x4a9): undefined reference to `ft_atoi'
collect2: error: ld returned 1 exit status
make: *** [Makefile:23: push_swap] Error 1
I believe the cause is the Makefile because it can't find the function that the makefile is suppose to compile too but im not sure about that.
Anyways here is my makefile:
NAME = push_swap
LIBFT_PATH = libft
LIBFT = libft.a
SRC_FILES = main.c
SRC_DIR = srcs/
SRC = ${addprefix ${SRC_DIR}, ${SRC_FILES}}
OBJ = ${SRC:.c=.o}
CC = gcc
CFLAGS = -Wall -Wextra -Werror -pg -g
AR = ar -rcs
%.o: %.c
${CC} -c -Imlx -c $< -o $#
all: ${NAME}
libft:
#MAKE -sC ${LIBFT_PATH}
${NAME}: libft ${OBJ}
${CC} ${LIBFT_PATH}/${LIBFT} ${OBJ} -o ${NAME}
clean:
rm -f ${OBJ}
${MAKE} -C ${LIBFT_PATH} clean
fclean: clean
rm -f ${NAME}
${MAKE} -C ${LIBFT_PATH} fclean
re: fclean all
.PHONY: all clean flcean re

gcc undefined reference to header of multiple files

I have a sample code temp.c:
#include "win.h"
win.h is in /home/me/Documents/Code/libs/TUI/win.h and has all the declared functions
which functions are defined in some files in /home/me/Documents/Code/libs/TUI/win/[lots of files].c which every file starts with
#include "../win.h"
//functions
So while using gcc -I /home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/me/Documents/Code/temp, gcc returns every function used in temp.c declared in win.h as undefined
Exact output:
gcc -g -I/home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/pk/Documents/Code/temp
/usr/bin/ld: /tmp/cc4berEn.o: in function `main':
/home/me/Documents/Code/temp.c:8: undefined reference to `innit'
/usr/bin/ld: /home/me/Documents/Code/temp.c:11: undefined reference to `newTable'
/usr/bin/ld: /home/me/Documents/Code/temp.c:13: undefined reference to `tableSetHeaders'
/usr/bin/ld: /home/me/Documents/Code/temp.c:35: undefined reference to `tableAppendRow'
/usr/bin/ld: /home/me/Documents/Code/temp.c:45: undefined reference to `printTable'
collect2: error: ld returned 1 exit status
notes
Using -I /home/me/Documents/Code/libs/TUI/win.h returns fatal error: win.h: No such file or directory 3 | #include "win.h"
/home/me/Documents/Code/libs/TUI is a folder
Writing every source file's name is not an option
Already tried this
-g for debug

Makefile: crt1.o: In function `_start': (.text+0x20): undefined reference to `main'

When I compile my makefile, I encounter this problem:
gcc parser.tab.o -o parser.tab
/usr/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
parser.tab.o: In function `yyparse':
parser.tab.c:(.text+0x2c3): undefined reference to `yylex'
parser.tab.c:(.text+0x3f5): undefined reference to `execute'
parser.tab.c:(.text+0x82b): undefined reference to `yyerror'
parser.tab.c:(.text+0x947): undefined reference to `yyerror'
collect2: ld returned 1 exit status
make: *** [parser.tab] Error 1
Here is my make file:
CC = gcc
CFLAGS = -lreadline
PROGS = d8sh parser.tab executor lexer
all: $(PROGS)
clean:
rm -f *.o $(PROGS) *.tmp
d8sh: d8sh.o
d8sh.o: executor.h lexer.h
executor.o: command.h
lexer.o: parser.tab.h
parser.tab.o: command.h
Only d8sh.c has a main function. Can anyone figure out what the problem is?

GCC: Undefined reference (Makefile issue)

Trying to compile these files with gcc under Makefile rules. Running gcc / make on cygwin.
Here's the makefile:
CC = gcc
CFLAGS = -g -O2 -Wall -std=c99
OBJECTS = simulation.o element.o
simulation.exe : $(OBJECTS)
$(CC) $(CFLAGS) -o simulation.exe $(OBJECTS)
simulation.o : file_priorite.o element.o
$(CC) $(CFLAGS) -c simulation.c
file_priorite.o: file_priorite.h element.o
$(CC) $(CFLAGS) -c file_priorite.c
element.o : element.h
$(CC) $(CFLAGS) -c element.c
clean:
rm -f *.o simulation.exe
And getting these errors:
CLEAN SUCCESSFUL (total time: 52ms)
gcc -g -O2 -Wall -std=c99 -c element.c
gcc -g -O2 -Wall -std=c99 -c simulation.c
gcc -g -O2 -Wall -std=c99 -o simulation.exe simulation.o element.o
simulation.o: In function `main':
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:11: undefined reference to `construire'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:11:(.text.startup+0x17): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `construire'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:20: undefined reference to `ajouter_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:20:(.text.startup+0x69): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `ajouter_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:23: undefined reference to `consommer_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:23:(.text.startup+0x76): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `consommer_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:23: undefined reference to `consommer_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:23:(.text.startup+0x86): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `consommer_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:25: undefined reference to `obtenir_taille'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:25:(.text.startup+0x96): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `obtenir_taille'
collect2: error: ld returned 1 exit status
Makefile:6: recipe for target 'simulation.exe' failed
make: *** [simulation.exe] Error 1
The problematic functions are all implemented in file_priorite.c.
Any idea?
You need to have
OBJECTS = simulation.o element.o file_priorite.o
Notice that your build log doesn't include file_priorite in any form - that means you're not building/linking against it. Add file_priorite.o to your OBJECTS line.

Cannot compile against gobject-2.0

I am trying to learn the gobject system, so I read some of the documentation on the gnome site and made a simple gobject parented to GObject. I don't wan't to keep running the gcc job every time I want to compile, and I also wanted to learn a build system at the same time. I tried autotools, which I got working to the point where pkg-config searches for gobject-2.0.
To compile my project from the command line, I do: gcc *.c $(pkg-config --cflags --libs gobject-2.0) (I had to take out the extra ticks for formatting). Anyway <--- this command works.
However: gcc $(pkg-config --cflags --libs gobject-2.0) *.c, which SHOULD BE the SAME COMMAND, returns this:
main.c: In function 'main':
main.c:10:10: warning: initialization from incompatible pointer type [enabled by default]
/tmp/ccxO7wkX.o: In function `main':
main.c:(.text+0x1a): undefined reference to `g_type_init'
main.c:(.text+0x27): undefined reference to `g_type_create_instance'
/tmp/ccPu2beU.o: In function `a_get_type':
myobject.c:(.text+0x57): undefined reference to `g_type_register_static'
collect2: ld returned 1 exit status
Yes, it is the EXACT SAME COMMAND WITH ANOTHER ORDER. I have no clue what's going wrong. Here is how autotools/automake does the build:
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lgobject-2.0 -lglib-2.0 -o GObjectTest main.o myobject.o
main.o: In function `main':
/home/aj/Desktop/GObjectTest/src/main.c:9: undefined reference to `g_type_init'
/home/aj/Desktop/GObjectTest/src/main.c:10: undefined reference to `g_type_create_instance'
myobject.o: In function `a_get_type':
/home/aj/Desktop/GObjectTest/src/myobject.c:19: undefined reference to `g_type_register_static'
collect2: ld returned 1 exit status
make: *** [GObjectTest] Error 1
Is this some quirky gcc compile thing? I tried with clang too no avail, which makes me think that this is a linker problem? I really have no idea, and was hoping that someone out there will. This is pretty frustrating.
Here is the "offending code":
GType a_get_type (void)
{
if (type == 0) {
GTypeInfo info = {
sizeof(AClass),
NULL,
NULL,
(GClassInitFunc) a_class_init,
NULL,
NULL,
sizeof(A),
0,
(GInstanceInitFunc) NULL
};
type = g_type_register_static (G_TYPE_OBJECT,
"AType",
&info, 0);
}
return type;
}
Edit: Here is the output of my autotools build, the make part anyway:
$ make
make all-recursive
make[1]: Entering directory `/home/aj/Desktop/GObjectTest'
Making all in src
make[2]: Entering directory `/home/aj/Desktop/GObjectTest/src'
gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
main.c: In function 'main':
main.c:10:10: warning: initialization from incompatible pointer type [enabled by default]
mv -f .deps/main.Tpo .deps/main.Po
gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -MT myobject.o -MD -MP -MF .deps/myobject.Tpo -c -o myobject.o myobject.c
mv -f .deps/myobject.Tpo .deps/myobject.Po
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lgobject-2.0 -lglib-2.0 -o GObjectTest main.o myobject.o
main.o: In function `main':
/home/aj/Desktop/GObjectTest/src/main.c:9: undefined reference to `g_type_init'
/home/aj/Desktop/GObjectTest/src/main.c:10: undefined reference to `g_type_create_instance'
myobject.o: In function `a_get_type':
/home/aj/Desktop/GObjectTest/src/myobject.c:19: undefined reference to `g_type_register_static'
collect2: ld returned 1 exit status
make[2]: *** [GObjectTest] Error 1
make[2]: Leaving directory `/home/aj/Desktop/GObjectTest/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/aj/Desktop/GObjectTest'
make: *** [all] Error 2
Here is the interesting part: replace gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lgobject-2.0 -lglib-2.0 -o GObjectTest main.o myobject.o with gcc -o GObjectTest main.o myobject.o -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lgobject-2.0 -lglib-2.0 and it works.

Resources