Newbie linking (ld) question (I think)

R

Rob

I think this is kind of a mish mash of understanding problems.

I have never needed to include an outside library before, and I am just
failing at every turn (Please keep in mind that I have never been taught C
I have only read books).

You might be able to help me without knowing my tools so please read on,
but here is my setup : Linux (2.4.20), the Anjuta IDE,
(anjuta.sourceforge.net) and the library I am trying to use is Scinitlla
(www.scintilla.org).

I think I can figure it out if I can just understand a couple things.

1) I have compiled the library and there are several object files and an
..a(?) file. In anjuta I have to specify a "library path" and a "library" -
this in turn is passed to ld (I think). Is the library path to the .o
files or .a file? and is the name of the library the .a file? (at least I
understand the include path :))

2) The library is written in C++, but I am using C for my program. There
is a setting in Anjuta to "use both C and C++" in the project - does that
appear to be in effect? (gcc not g++)?


At present I have the library path set to point to the .a file. When I
make this is where errors happen:
[key]
(/home/rob/Projects/scintilla/bin/ = the .a file - scintilla.a)
(/home/rob/Projects/scintilla/include/ = the .h files)
(/home/rob/Projects/scintilla/gtk/ = .o files)
[/key]
-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
make[2]: Entering directory `/home/rob/Projects/bregalad/src' /bin/sh
.../libtool --mode=link gcc -g -O2 -o bregalad
-L/home/rob/Projects/scintilla/bin/ bregalad-main.o -Wl ,--export-dynamic
-lgtk-x11-2.0 -latk-1.0 -lgdk-x11-2.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
-lgthread

gcc -g -O2 -o bregalad bregalad-main.o -Wl,--export-dynamic
-L/home/rob/Projects/scintilla/bin/ -lgtk-x11-2.0 - latk-1.0 -lgdk-x11-2.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 /usr/lib/libgthread.so -lpthread

[boom - it can't find the library?]
bregalad-main.o(.text+0x3f): In function `main':
/home/rob/Projects/bregalad/src/main.c:20: undefined reference to
`scintilla_new'
bregalad-main.o(.text+0x46):/home/rob/Projects/bregalad/src/main.c:21:
undefined reference to `scintilla_get_typ e'
bregalad-main.o(.text+0xa7):/home/rob/Projects/bregalad/src/main.c:27:
undefined reference to `scintilla_set_id'

....[snip]...

bregalad-main.o(.text+0x123):/home/rob/Projects/bregalad/src/main.c:54:
more undefined references to `scintilla_ send_message' follow
collect2: ld returned 1 exit status

Again sorry for my lack of knowledge I have written many program, and
never needed to do anything like this before. Times like these I remember
how little I actaully know.

Thanks in advance (and Cheers to UKers),
Rob
 
G

Giuseppe

I think this is kind of a mish mash of understanding problems.

I have never needed to include an outside library before, and I am just
failing at every turn (Please keep in mind that I have never been taught C
I have only read books).

You might be able to help me without knowing my tools so please read on,
but here is my setup : Linux (2.4.20), the Anjuta IDE,
(anjuta.sourceforge.net) and the library I am trying to use is Scinitlla
(www.scintilla.org).

I think I can figure it out if I can just understand a couple things.

1) I have compiled the library and there are several object files and an
.a(?) file. In anjuta
What is "anjuta"?
Here you speak of .a (static) but then you write .so (dynamic)
I have to specify a "library path" and a "library" -
this in turn is passed to ld (I think). Is the library path to the .o
files or .a file? and is the name of the library the .a file? (at least I
understand the include path :))

2) The library is written in C++, but I am using C for my program. There
is a setting in Anjuta to "use both C and C++" in the project - does that
appear to be in effect? (gcc not g++)?
At present I have the library path set to point to the .a file. When I
make this is where errors happen:
[key]
(/home/rob/Projects/scintilla/bin/ = the .a file - scintilla.a)
here you write scintilla.a but where is it then?
(/home/rob/Projects/scintilla/include/ = the .h files)
(/home/rob/Projects/scintilla/gtk/ = .o files)
[/key]
-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
make[2]: Entering directory `/home/rob/Projects/bregalad/src' /bin/sh
../libtool --mode=link gcc -g -O2 -o bregalad
-L/home/rob/Projects/scintilla/bin/ bregalad-main.o -Wl ,
--export-dynamic ..a are static .so are dynamic
-lgtk-x11-2.0 -latk-1.0 -lgdk-x11-2.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
-lgthread

gcc -g -O2 -o bregalad bregalad-main.o -Wl,--export-dynamic
-L/home/rob/Projects/scintilla/bin/ -lgtk-x11-2.0 - latk-1.0 -lgdk-x11-2.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 /usr/lib/libgthread.so -lpthread

[boom - it can't find the library?]
bregalad-main.o(.text+0x3f): In function `main':
/home/rob/Projects/bregalad/src/main.c:20: undefined reference to
`scintilla_new'
bregalad-main.o(.text+0x46):/home/rob/Projects/bregalad/src/main.c:21:
undefined reference to `scintilla_get_typ e'
bregalad-main.o(.text+0xa7):/home/rob/Projects/bregalad/src/main.c:27:
undefined reference to `scintilla_set_id'

If you have C files
a.c, b.c, t.c
full of functions and
the header that has the prototypes of this function is
header.h
and if all of these files are in the same dir /dir

and if libMMM.a is the lib name that you want to create (you have to
see that it begin with lib* and end with *.a for static libs)
you in Linux can do
$ gcc -c a.c
$ gcc -c b.c
$ gcc -c t.c
for build .o files

$ ar r libMMM.a a.o b.o c.o
for build static libMMM.a library in /dir

If you want to use that lib with /dir/file.c
/*file.c*/
#include "header.h"
......
/*EOF*/
$ gcc -c file.c
$ gcc file.o libMMM.a -o file
build file
$ file
run file

if you have C++ files, replace gcc with g++ over.

if your file.c is in dir2/
in dir2 you can try
$ gcc file.o -L/dir libMMM.a -o file

If your library are .so you have to change
LD_LIBRARY_PATH
or you have to write in /etc/ld.so.conf for path

if you have Vide editor and ide
in tool-> setup tool write for C++
g++= %*%_ g++ -c %F; g++ %R.o libMMM.a -o %R %>
or
gcc= %*%_ gcc -c %F; gcc %R.o libMMM.a -o %R %>
for C
But man pages doesn't have a e.g.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top