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?
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
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)
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.