Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Linking Error, possible makefile problem
Linking Error, possible makefile problem [message #142571] Mon, 04 April 2005 17:50 Go to next message
Eclipse UserFriend
Originally posted by: janst_nwgs.freenet.de

Hello all,
in short, i am trying to compile an (Makefile) Managed C++ GTKmm hello
world app.
But i always get an strange linking error with the following message:

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

OK, i know what that means, he cannot find my main function, which has
actually the correct signature and return val plus a nice definition :D
=> int main (int argc, char** argv)
{...

I guess there must be some problem with the make file because an simple

g++ Main.cpp RndStat.cpp `pkg-config --cflags --libs gtk+-2.0`
`pkg-config gtkmm-2.4 --libs --cflags`

works without problems.

The directory structure is:
/
- Main.h
- Main.cpp
- RndStat.h
- RndStat.cpp

Anybody got an idea what the problem might be or how to solve it...
Thank you in advcance

jan
Re: Linking Error, possible makefile problem [message #142580 is a reply to message #142571] Mon, 04 April 2005 18:03 Go to previous messageGo to next message
Eclipse UserFriend
El lun, 04-04-2005 a las 23:50 +0200, Jan escribió:

> But i always get an strange linking error with the following message:
>
> crt1.o(.text+0x18): In function `_start':
> : undefined reference to `main'
>
> OK, i know what that means, he cannot find my main function, which has
> actually the correct signature and return val plus a nice definition :D

Make sure that the file that contains the definition for the main
function is being linked in the executable. I'm not sure whether it
matters, but check that you're using g++ to link if you use it to
compile.

Greetings,
--
Javier Kohen <jkohen@users.sourceforge.net>
ICQ: blashyrkh #2361802
Jabber: jkohen@jabber.org
Re: Linking Error, possible makefile problem [message #142689 is a reply to message #142580] Tue, 05 April 2005 17:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: janst_nwgs.freenet.de

Javier Kohen schrieb:
> El lun, 04-04-2005 a las 23:50 +0200, Jan escribió:
> Make sure that the file that contains the definition for the main
> function is being linked in the executable.

Yes, and now the 1.000.000$ question:
Any ideas how to do that (in a Managed C++ Project:D )?
Greetings jan
Re: Linking Error, possible makefile problem [message #142699 is a reply to message #142689] Tue, 05 April 2005 17:23 Go to previous messageGo to next message
Eclipse UserFriend
El mar, 05-04-2005 a las 23:00 +0200, Jan escribió:
> Javier Kohen schrieb:
> > El lun, 04-04-2005 a las 23:50 +0200, Jan escribió:
> > Make sure that the file that contains the definition for the main
> > function is being linked in the executable.
>
> Yes, and now the 1.000.000$ question:
> Any ideas how to do that (in a Managed C++ Project:D )?

Hm... I guess that you have to be lucky, I only tried C Managed projects
(libraries and binaries) and they work here ;-)

Can you post the commands that are being run during linking and
compilation, to see whether there is an attempt to link this particular
object or not?

--
Javier Kohen <jkohen@users.sourceforge.net>
ICQ: blashyrkh #2361802
Jabber: jkohen@jabber.org
Re: Linking Error, possible makefile problem [message #142756 is a reply to message #142699] Wed, 06 April 2005 13:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: janst_nwgs.freenet.de

Javier Kohen schrieb:
> Can you post the commands that are being run during linking and
> compilation, to see whether there is an attempt to link this particular
> object or not?
Ok, i just wanted to wait until somone really wants to see it :D..
Here we go:

Main.h
Main.cpp
RndStat.cpp
RndStat.h

and as I said, a simple
"g++ Main.cpp RndStat.cpp `pkg-config --cflags --libs gtk+-2.0`
`pkg-config gtkmm-2.4 --libs --cflags` " is successful..
The makefile is at the bottom..

make -k all
Building file: ../Main.cpp
g++ -I/usr/include/gtk -I/usr/include/gtkmm-2.4 -O0 -g3 -Wall -DXTHREADS
-D_REENTRANT -DXUSE_MTSAFE_API -I/usr/include/gtk-2.0
-I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/atk-1.0
-I/usr/include/pango-1.0 -I/usr/include/freetype2
-I/usr/include/freetype2/config -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include -Wl,--export-dynamic -lgtk-x11-2.0
-lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0
-lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -DXTHREADS
-D_REENTRANT -DXUSE_MTSAFE_API -I/usr/include/gtkmm-2.4
-I/usr/lib/gtkmm-2.4/include -I/usr/include/glibmm-2.4
-I/usr/lib/glibmm-2.4/include -I/usr/include/gdkmm-2.4
-I/usr/lib/gdkmm-2.4/include -I/usr/include/pangomm-1.4
-I/usr/include/atkmm-1.6 -I/usr/include/gtk-2.0
-I/usr/include/sigc++-2.0 -I/usr/lib/sigc++-2.0/include
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/pango-1.0
-I/usr/include/freetype2 -I/usr/include/freetype2/config
-I/usr/include/atk-1.0 -Wl,--export-dynamic -lgtkmm-2.4 -lgdkmm-2.4
-latkmm-1.6 -lgtk-x11-2.0 -lpangomm-1.4 -lglibmm-2.4 -lsigc-2.0
-lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0
-lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -oMain.o ../Main.cpp
/tmp/ccisnknl.o(.text+0x1eb): In function `main':
.../Main.cpp:20: undefined reference to `RndStat::RndStat()'
/tmp/ccisnknl.o(.text+0x22b):../Main.cpp:25: undefined reference to
`RndStat::~RndStat()'
/tmp/ccisnknl.o(.text+0x267):../Main.cpp:25: undefined reference to
`RndStat::~RndStat()'
Building file: ../RndData.cpp
collect2: ld gab 1 als Ende-Status zurück
make: *** [Main.o] Fehler 1
g++ -I/usr/include/gtk -I/usr/include/gtkmm-2.4 -O0 -g3 -Wall -DXTHREADS
-D_REENTRANT -DXUSE_MTSAFE_API -I/usr/include/gtk-2.0
-I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/atk-1.0
-I/usr/include/pango-1.0 -I/usr/include/freetype2
-I/usr/include/freetype2/config -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include -Wl,--export-dynamic -lgtk-x11-2.0
-lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0
-lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -DXTHREADS
-D_REENTRANT -DXUSE_MTSAFE_API -I/usr/include/gtkmm-2.4
-I/usr/lib/gtkmm-2.4/include -I/usr/include/glibmm-2.4
-I/usr/lib/glibmm-2.4/include -I/usr/include/gdkmm-2.4
-I/usr/lib/gdkmm-2.4/include -I/usr/include/pangomm-1.4
-I/usr/include/atkmm-1.6 -I/usr/include/gtk-2.0
-I/usr/include/sigc++-2.0 -I/usr/lib/sigc++-2.0/include
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/pango-1.0
-I/usr/include/freetype2 -I/usr/include/freetype2/config
-I/usr/include/atk-1.0 -Wl,--export-dynamic -lgtkmm-2.4 -lgdkmm-2.4
-latkmm-1.6 -lgtk-x11-2.0 -lpangomm-1.4 -lglibmm-2.4 -lsigc-2.0
-lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0
-lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -oRndData.o
.../RndData.cpp
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../crt1.o(.text+0 x18): In
function `_start':
: undefined reference to `main'
collect2: ld gab 1 als Ende-Status zurück
make: *** [RndData.o] Fehler 1
Building file: ../RndStat.cpp
g++ -I/usr/include/gtk -I/usr/include/gtkmm-2.4 -O0 -g3 -Wall -DXTHREADS
-D_REENTRANT -DXUSE_MTSAFE_API -I/usr/include/gtk-2.0
-I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/atk-1.0
-I/usr/include/pango-1.0 -I/usr/include/freetype2
-I/usr/include/freetype2/config -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include -Wl,--export-dynamic -lgtk-x11-2.0
-lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0
-lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -DXTHREADS
-D_REENTRANT -DXUSE_MTSAFE_API -I/usr/include/gtkmm-2.4
-I/usr/lib/gtkmm-2.4/include -I/usr/include/glibmm-2.4
-I/usr/lib/glibmm-2.4/include -I/usr/include/gdkmm-2.4
-I/usr/lib/gdkmm-2.4/include -I/usr/include/pangomm-1.4
-I/usr/include/atkmm-1.6 -I/usr/include/gtk-2.0
-I/usr/include/sigc++-2.0 -I/usr/lib/sigc++-2.0/include
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/pango-1.0
-I/usr/include/freetype2 -I/usr/include/freetype2/config
-I/usr/include/atk-1.0 -Wl,--export-dynamic -lgtkmm-2.4 -lgdkmm-2.4
-latkmm-1.6 -lgtk-x11-2.0 -lpangomm-1.4 -lglibmm-2.4 -lsigc-2.0
-lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0
-lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -oRndStat.o
.../RndStat.cpp
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../crt1.o(.text+0 x18): In
function `_start':
: undefined reference to `main'
collect2: ld gab 1 als Ende-Status zurück
make: *** [RndStat.o] Fehler 1
make: Das Target »all« wurde wegen Fehlern nicht aktualisiert.
Build complete for project RndStat

############################################################ ####################
# Automatically-generated file. Do not edit!
############################################################ ####################

ROOT := ..

-include $(ROOT)/makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include $(SUBDIRS:%=%/subdir.mk)
-include objects.mk
-include $(DEPS)
-include $(ROOT)/makefile.defs

all: RndStat

RndStat: $(OBJS)
@echo 'Building target: $@'
g++ -L/home/jan/eclipse/workspace/RndStat -o $@ $(OBJS) $(USER_OBJS)
$(LIBS)
@echo 'Finished building: $@'

clean:
-$(RM) $(OBJS) $(DEPS) RndStat

..PHONY: all clean dependents

-include $(ROOT)/makefile.targets
Re: Linking Error, possible makefile problem [message #142764 is a reply to message #142756] Wed, 06 April 2005 13:44 Go to previous messageGo to next message
Eclipse UserFriend
Hallo Jan,

El mié, 06-04-2005 a las 19:25 +0200, Jan escribió:
> Javier Kohen schrieb:
> > Can you post the commands that are being run during linking and
> > compilation, to see whether there is an attempt to link this particular
> > object or not?

> make -k all
> Building file: ../Main.cpp
> g++ -I/usr/include/gtk -I/usr/include/gtkmm-2.4 -O0 -g3 -Wall -DXTHREADS
> -D_REENTRANT -DXUSE_MTSAFE_API -I/usr/include/gtk-2.0
> -I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/atk-1.0
> -I/usr/include/pango-1.0 -I/usr/include/freetype2
> -I/usr/include/freetype2/config -I/usr/include/glib-2.0
> -I/usr/lib/glib-2.0/include -Wl,--export-dynamic -lgtk-x11-2.0
> -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0
> -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -DXTHREADS
> -D_REENTRANT -DXUSE_MTSAFE_API -I/usr/include/gtkmm-2.4
> -I/usr/lib/gtkmm-2.4/include -I/usr/include/glibmm-2.4
> -I/usr/lib/glibmm-2.4/include -I/usr/include/gdkmm-2.4
> -I/usr/lib/gdkmm-2.4/include -I/usr/include/pangomm-1.4
> -I/usr/include/atkmm-1.6 -I/usr/include/gtk-2.0
> -I/usr/include/sigc++-2.0 -I/usr/lib/sigc++-2.0/include
> -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
> -I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/pango-1.0
> -I/usr/include/freetype2 -I/usr/include/freetype2/config
> -I/usr/include/atk-1.0 -Wl,--export-dynamic -lgtkmm-2.4 -lgdkmm-2.4
> -latkmm-1.6 -lgtk-x11-2.0 -lpangomm-1.4 -lglibmm-2.4 -lsigc-2.0
> -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0
> -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -oMain.o ../Main.cpp
> /tmp/ccisnknl.o(.text+0x1eb): In function `main':
> ../Main.cpp:20: undefined reference to `RndStat::RndStat()'
> /tmp/ccisnknl.o(.text+0x22b):../Main.cpp:25: undefined reference to
> `RndStat::~RndStat()'
> /tmp/ccisnknl.o(.text+0x267):../Main.cpp:25: undefined reference to
> `RndStat::~RndStat()'
> Building file: ../RndData.cpp
> collect2: ld gab 1 als Ende-Status zurück

Your compiler settings are wrong. It's trying to generate a executable
called Main.o and not an intermediate object. You can tell because the
-c gcc switch is missing and because it's trying to link a lot of
libraries into a .o file.

I don't know how to fix it in your case with CDT, but I guess you have
to convince it to compile from .cpp to .o instead of doing a full link.

Greetings,
--
Javier Kohen <jkohen@users.sourceforge.net>
ICQ: blashyrkh #2361802
Jabber: jkohen@jabber.org
Re: Linking Error, possible makefile problem [message #142774 is a reply to message #142764] Wed, 06 April 2005 14:36 Go to previous message
Eclipse UserFriend
Originally posted by: janst_nwgs.freenet.de

> Your compiler settings are wrong. It's trying to generate a executable
> called Main.o and not an intermediate object. You can tell because the
> -c gcc switch is missing and because it's trying to link a lot of
> libraries into a .o file.
>
> I don't know how to fix it in your case with CDT, but I guess you have
> to convince it to compile from .cpp to .o instead of doing a full link.

Hello Javier,

thank you for this information. Due to I am new to gcc, make and gtkmm
at one time :D this really makes it easier..!

Jan
Previous Topic:PC environment variables
Next Topic:Java Developer Journal and Linux World Awards
Goto Forum:
  


Current Time: Sat May 10 15:40:29 EDT 2025

Powered by FUDForum. Page generated in 0.03700 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top