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 0000000008048184
?What does that mean? How can I prevent it?
obj/hello.o(.text+0x17): In function `main':
: undefined reference to `msg_1'
obj/hello.o(.text+0x1c): 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 3 8608
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
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********************@news.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
0000000008048184 ?What does that mean? How can I prevent it?
obj/hello.o(.text+0x17): In function `main': : undefined reference to `msg_1' obj/hello.o(.text+0x1c): 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
In <20********************@news.arcor-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 0000000008048184
?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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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>...
|
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%...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
-----------------------
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
| |