473,698 Members | 2,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

gcc linker problem

Hello,

I must be doing something wrong, but I don't get it:

- compile
gcc -c -O -Iinc src/hello.c -o obj/hello.o
gcc -c -O -Iinc src/msg_1.c -o obj/msg_1.o
gcc -c -O -Iinc src/msg_2.c -o obj/msg_2.o

- make library
ar -cru lib/libhello.a obj/msg_1.o obj/msg_2.o
ranlib lib/libhello.a

- link
ld -o exe/hello.x -t -Llib -lhello -lc obj/hello.o

ld: mode elf_i386
/lib/libc.so.6
obj/hello.o

?Why is ./lib/libhello.a missing here?

ld: warning: cannot find entry symbol start; defaulting to 000000000804818 4

?What does that mean? How can I prevent it?

obj/hello.o(.text+0 x17): In function `main':
: undefined reference to `msg_1'
obj/hello.o(.text+0 x1c): In function `main':
: undefined reference to `msg_2'
ld: link errors found, deleting executable `exe/hello.x'

Check ./lib/libhello.a:

nm -s lib/libhello.a

Archive index:
msg_1 in msg_1.o
msg_2 in msg_2.o

msg_1.o:
00000000 T msg_1
U puts

msg_2.o:
00000000 T msg_2
U puts

There functions are in the archive. So why does the linker not find them?
Does anyone see my mistake?
I am working with SuSE Linux.
Bye,

Georg
Nov 13 '05 #1
3 8666
Georg <no.spam@all> wrote:
There functions are in the archive. So why does the linker not find them?
Does anyone see my mistake?


No idea; ask in a gcc group. Try, for example, gnu.gcc.help.

But you could have the decency to read their FAQ first.

Richard
Nov 13 '05 #2
georg-

looks like a problem with your linker configuration. possibly, the object
file that contains the *true* entry point is not getting linked. it is part
of the c run time and for suse this is the "_start" symbol. possibly your
default linker script has been overridden. see the default link script for
details.

-bryan

"Georg" <no.spam@all> wrote in message
news:20******** ************@ne ws.arcor-ip.de...
Hello,

I must be doing something wrong, but I don't get it:

- compile
gcc -c -O -Iinc src/hello.c -o obj/hello.o
gcc -c -O -Iinc src/msg_1.c -o obj/msg_1.o
gcc -c -O -Iinc src/msg_2.c -o obj/msg_2.o

- make library
ar -cru lib/libhello.a obj/msg_1.o obj/msg_2.o
ranlib lib/libhello.a

- link
ld -o exe/hello.x -t -Llib -lhello -lc obj/hello.o

ld: mode elf_i386
/lib/libc.so.6
obj/hello.o

?Why is ./lib/libhello.a missing here?

ld: warning: cannot find entry symbol start; defaulting to 000000000804818 4
?What does that mean? How can I prevent it?

obj/hello.o(.text+0 x17): In function `main':
: undefined reference to `msg_1'
obj/hello.o(.text+0 x1c): In function `main':
: undefined reference to `msg_2'
ld: link errors found, deleting executable `exe/hello.x'

Check ./lib/libhello.a:

nm -s lib/libhello.a

Archive index:
msg_1 in msg_1.o
msg_2 in msg_2.o

msg_1.o:
00000000 T msg_1
U puts

msg_2.o:
00000000 T msg_2
U puts

There functions are in the archive. So why does the linker not find them?
Does anyone see my mistake?
I am working with SuSE Linux.
Bye,

Georg

Nov 13 '05 #3
In <20************ ********@news.a rcor-ip.de> Georg <no.spam@all> writes:
I must be doing something wrong, but I don't get it:

- compile
gcc -c -O -Iinc src/hello.c -o obj/hello.o
gcc -c -O -Iinc src/msg_1.c -o obj/msg_1.o
gcc -c -O -Iinc src/msg_2.c -o obj/msg_2.o

- make library
ar -cru lib/libhello.a obj/msg_1.o obj/msg_2.o
ranlib lib/libhello.a

- link
ld -o exe/hello.x -t -Llib -lhello -lc obj/hello.o
The thing you're doing wrong is using ld yourself. The ld command is for
super-gurus ONLY, the rest of the mortals are supposed to invoke it
through the compiler interface, gcc in your case.

Let's have a look at what gcc does for the most trivial linking job:

fangorn:~/tmp 1670> gcc -v test.o
Reading specs from /products/gnu/gcc2/v2.95.3/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/specs
gcc version 2.95.3 20010315 (release)
/products/gnu/gcc2/v2.95.3/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /products/gnu/gcc2/v2.95.3/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/crtbegin.o -L/products/gnu/gcc2/v2.95.3/lib/gcc-lib/i686-pc-linux-gnu/2.95.3 -L/products/gnu/gcc2/v2.95.3/lib test.o -lgcc -lc -lgcc /products/gnu/gcc2/v2.95.3/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/crtend.o /usr/lib/crtn.o

That's quite a bit more complex than your simple minded ld command, isn't
it? A number of "mysterious " object files (crt1.o, crti.o, crtbegin.o,
crtend.o, crtn.o) get linked behind my back, in a well defined
order WRT the rest of the files and libraries, to get a *working*
executable file. As a mere mortal, I'm quite happy that I don't have
to learn to type such ld commands myself. Especially considering that
the paths involved differ from one installation to another.
ld: mode elf_i386
/lib/libc.so.6
obj/hello.o

?Why is ./lib/libhello.a missing here?
Most likely because you put -lhello *before* obj/hello.o on the
command line. By the time ld processed the -lhello option, it found
nothing interesting in it, so it discarded it. The golden rule is that
each library must follow the object files/libraries that contain
references to it. In the case when two libraries contain crossed
references, mention one of them twice: -lfoo -lbar -lfoo.

So, you may have better success with the following command:

gcc -o exe/hello.x -Wl,-t obj/hello.o -Llib -lhello

No need for -lc, it's linked by default, and -Wl,-t is the canonical
way of passing the -t option to the linker. Because gcc itself has no
-t option, in this particular case a plain -t would have worked, as well.
But the -Wl option works even in the case of a conflict between gcc
options and ld options and it's faster to just use it than to check
whether such a conflict exists or not.
ld: warning: cannot find entry symbol start; defaulting to 000000000804818 4

?What does that mean? How can I prevent it?


It means that you didn't include the mysterious object files mentioned
above into the ld argument list. The gcc command will do it for you.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9394
by: haplotype | last post by:
I have designed a package with several files, which is listed bellow base.cpp & base.hpp - define the template class base tree.cpp & tree.hpp - define the class tree derived from base<int> client.cpp & client.hpp - define the class client derived from tree main.cpp - the main function instantiate client and run All these files are compiled successfully, but there's a linker error " undefined reference to `base<int>::base_run()' ". ...
2
2126
by: Joske | last post by:
Hi, I'm having a similar problem as Scott. A static library with managed C++ functions fails to link in. See http://groups.google.be/groups?q=managed+C%2B% 2B+static+library&start=10&hl=en&lr=&ie=UTF-8&oe=UTF- 8&selm=uXE2ZMiqDHA.2644%40TK2MSFTNGP09.phx.gbl&rnum=14 (BTW why can I find scott's post with Google and not using the msdn web-interface? It seems to have vanished)
4
11325
by: Saran | last post by:
Hi All, I'm getting the following linker error when I try to build a library. nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc nafxcw.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype nafxcw.lib(filelist.obj) : error LNK2019: unresolved external symbol __mbctype referenced in function "void __stdcall...
3
1773
by: Steve Baer | last post by:
I recently read your whitepaper under the "extremely long link times" post and have a question that I was hoping you could answer. My question is based on the following paragraph: Directives The linker's handling of directives left something to be desired in VC2003, and for this reason code with lots of directives can suffer. In particular __declspec(export), as it's likely the most common linker directive. Besides that, don't export...
9
2004
by: Peter Oliphant | last post by:
For some reson my code is generating a LNK1215 error, which 'suggests' I re-install VS C++. So I did. which did NOT solve the problem. The weid part is it seems to be caused by my one CPP file, but not sure how. It compiled just fine. Then I made a simple change and re-compiled, and got the 1215 error. After that I have to bring back in an old version of the code to make it work again (not fun)... This seems like a REAL LINKER error, not...
3
3293
by: ralphsieminsky | last post by:
A project compiles fine under VS 2005 RC without the /clr option. However, when /clr is turned on several errors appear: - A symbol exported from a DLL is not found by another DLL referencing it. The name of the symbol present in the DLL, as shown by depends.exe is ?Apply@ScreenContext@@SGPAV1@PAUHWND__@@@Z But the name of the symbol the linker looks for when
1
2262
by: Felix | last post by:
After porting a project from VC6 to VC.NET 2003 I have a very strange problem generating link error 1104 for import libraries. I just ported the project and made some small adaptions so it fits the new IDE. The project itself links against some import libraries belonging to dll's I wrote (these dll's have been ported too, of course). To keep things simple I only use one import library here. To tell the linker it should link against
2
2794
by: Robbie Hatley | last post by:
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote: > Robbie Hatley wrote: > > > > I ran into a problem a few days ago when I added a couple of > > template functions to one of my personal library headers. > > > > My library, librh.a > > Linking is not defined by C++ .
1
4159
by: Deepath G | last post by:
This is deepath.. I am getting some linker error when i am trying to connect Websphere MQ using Borland C++ Builder 2006 using imqi.hpp on windows. Error Message ----------------------- Error: Unresolved external 'ImqMgr::~ImqMgr()' referenced from C:\DOCUMENTS AND SETTINGS\228753\MY DOCUMENTS\BORLAND STUDIO PROJECTS\DLLEXERCISE\DEBUG_BUILD\MANI.OBJ Error: Unresolved external 'ImqObj::~ImqObj()' referenced from C:\DOCUMENTS AND...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.