GCC: Undefined reference (Makefile issue) - c

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.

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

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?

undefined references when building xulrunner

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.

cygwin make - undefined referance to INT_MAX and argp_usage

I've not written this program myself nor am I experienced with cygwin and linux but from what I can tell the file seems to have the right include:
// tsim_argp.c
#include <argp.h>
#include <stdlib.h>
#include <unistd.h> /* nice */
#include "tsim_argp.h"
argp.h which contains argp_usage also got limits.h included which contains INT_MAX so what exactly am I missing? I got all the other c-files compiling just fine it's just this last one that's causing problem.
make dialogue:
...
Making all in src
make[2]: Entering directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
gcc -DHAVE_CONFIG_H -I. -I.. -std=gnu99 -pedantic -Wall -Wextra -Wmissing-pro
totypes -DRESDIR=\"/c/Users/David/Downloads/Train_Simulator/share/tsim\" -g -O2
-MT tsim-tsim_argp.o -MD -MP -MF .deps/tsim-tsim_argp.Tpo -c -o tsim-tsim_argp.o
`test -f 'tsim_argp.c' || echo './'`tsim_argp.c
tsim_argp.c: In function 'setpriority':
tsim_argp.c:170:19: error: 'INT_MAX' undeclared (first use in this function)
if( priority == INT_MAX ) {
^
tsim_argp.c:170:19: note: each undeclared identifier is reported only once for e
ach function it appears in
...
Makefile:479: recipe for target 'tsim-tsim_argp.o' failed
make[2]: *** [tsim-tsim_argp.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
Makefile:247: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84'
Makefile:169: recipe for target 'all' failed
make: *** [all] Error 2
make dialogue if I include the limits.h library directly in tsim_argp:
...
Making all in src
make[2]: Entering directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
gcc -std=gnu99 -pedantic -Wall -Wextra -Wmissing-prototypes -DRESDIR=\"/c/Users/
David/Downloads/Train_Simulator/share/tsim\" -g -O2 -L/usr/X11R6/lib -lXaw -lXt
-lXmu -lX11 -lXext -o tsim.exe tsim-AddToggleWidget.o tsim-DialogPopup.o tsim-f
ile.o tsim-resources.o tsim-timer.o tsim-tsim.o tsim-bitmap.o tsim-DrawingPalett
e.o tsim-Graph.o tsim-sound.o tsim-train.o tsim-BitmapDirectory.o tsim-errcheck.
o tsim-pipe.o tsim-Sprite.o tsim-tsim_argp.o -lXt -lXmu -lXext -lXaw -lX11
tsim-tsim_argp.o: In function `parse_opt':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:113: undefined refer
ence to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:113:(.text+0xbe): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:83: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:83:(.text+0x10e): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:98: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:98:(.text+0x15c): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:68: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:68:(.text+0x1a3): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:118: undefined refer
ence to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:118:(.text+0x294): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
tsim-tsim_argp.o:/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:103
: more undefined references to `argp_usage' follow
tsim-tsim_argp.o: In function `parse_opt':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:103:(.text+0x2c4): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:73:(.text+0x2f4): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:88:(.text+0x324): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:127:(.text+0x354): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
tsim-tsim_argp.o: In function `parse':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:234: undefined refer
ence to `argp_parse'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:234:(.text+0x429): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_parse'
collect2: error: ld returned 1 exit status
Makefile:228: recipe for target 'tsim.exe' failed
make[2]: *** [tsim.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
Makefile:247: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84'
Makefile:169: recipe for target 'all' failed
make: *** [all] Error 2
In Cygwin, it looks like argp is separate library. You'll need to add: -largp to your gcc 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