Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (GNU/Linux, *NIX, *BSD und Co) » static library

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
13.03.2006, 18:19 Uhr
daxiaoaixad



Hi, I have a problem.

In directory hi I have files fl.h and fl.cc. In file fl.h I have only the line:
int GetFlow (char* file );

In file fl.c I have defined the function:
...
int GetFlow (char* file )
{
...}

Then I used
gcc -c fl.c
ar rc libflow.a fl.o

to generate the library.

In another file mm.c I have

#include "hi_pr.h"

...


void run(){
char* file = "output_flow.txt";

GetFlow(file);

return 0;
}

I can get the objective: mm.o, but if I compile:
g++ -o static -I../hi/flow mm.o ../hi/libflow.a -ldl

I got the following error message:

MaxFlow.o(.text+0xc03): In function `MaxFlow::run_flow()':
/zhanglijun/svn/personal/papers/weak_simulation_implementation/simulation/MaxFlow.cc:378: undefined reference to `GetFlow(char*)'
collect2: ld returned 1 exit status
make: *** [flow_static] Error 1

can somebody give me some suggestions where is wrong?

thank you!
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
13.03.2006, 18:42 Uhr
0xdeadbeef
Gott
(Operator)


From what I can tell,

Code:
g++ -o static -ldl -lflow -L../hi mm.o


is what you want. This produces a binary called "static" linked against libdl.a and libflow.a (and the standard libraries) and searches ../hi for those libraries (and the default paths). Unless ../hi is known to the linker, you will also have to specify that directory when you run the binary, ie

Code:
LD_LIBRARY_PATH=../hi ./static


--
Einfachheit ist Voraussetzung für Zuverlässigkeit.
-- Edsger Wybe Dijkstra
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
13.03.2006, 21:23 Uhr
~daxiaoaixad
Gast


Hi, thank you for your anser. But this still does't solve my problem.

I think


Code:
g++ -o static -I../hi/flow mm.o ../hi/libflow.a -ldl



and


Zitat von 0xdeadbeef:
From what I can tell,

Code:
g++ -o static -ldl -lflow -L../hi mm.o





are the same. After the try, I got the same error message.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
13.03.2006, 22:11 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


perhaps the "GetFlow"-functions is removed in the optimizing step?
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
004
13.03.2006, 22:44 Uhr
virtual
Sexiest Bit alive
(Operator)


Maybe you should ensure that GetFlow is exported with C linkage:
Place in the header

C++:
extern "C" {

int GetFlow (char* file ):

... other symbols to export from .c files ...
}


or so.

Mixing C and C++ means to specify the correct linkage when declaring functions:
C++ linkage uses "mangled names" - when generating the library symbols it uses the function name plus some characters describing which parameters are passed to the function. In opposite to that C uses just the plain function name. This is because in C++ the linker must be able to distinguish functions by their signatures, not just names.
--
Gruß, virtual
Quote of the Month
Ich eß' nur was ein Gesicht hat (Creme 21)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
005
13.03.2006, 23:06 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


i'll move that to linux now
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
006
14.03.2006, 14:41 Uhr
daxiaoaixad



after I include the:


Code:
#ifdef __cplusplus
extern "C"
{
#endif

int GetFlow (char* file );

#ifdef __cplusplus
}
#endif


it works now! Thank you!!



Zitat von virtual:
Maybe you should ensure that GetFlow is exported with C linkage:
Place in the header

C++:
extern "C" {

int GetFlow (char* file ):

... other symbols to export from .c files ...
}


or so.

Mixing C and C++ means to specify the correct linkage when declaring functions:
C++ linkage uses "mangled names" - when generating the library symbols it uses the function name plus some characters describing which parameters are passed to the function. In opposite to that C uses just the plain function name. This is because in C++ the linker must be able to distinguish functions by their signatures, not just names.

Dieser Post wurde am 14.03.2006 um 14:41 Uhr von daxiaoaixad editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (GNU/Linux, *NIX, *BSD und Co) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: