c++ - What g++ link option to fix the error function not found -
my project uses g++ compiler compile source code distributed on several directories, executable built. in building final executable link error function not defined.
i cooked following code scaled down of project , exposes same error, hope me out.
so here directory tree , source files:
./ ./11/ c1.cpp c1.h ./12/ c2.cpp
here files:
./11/c1.h: int f(); ./11/c1.cpp: #include "c1.h" int f() { return 0; } ./12/c2.cpp: #include "c1.h" int main() { f(); return 0; }
here steps build files:
cd 11 g++ -c -o ../c1.o c1.cpp cp c1.h .. cd .. ar cr libc1.a c1.o cd 12 g++ -i../ -l../ -lc1 c2.cpp
yes, need compile c1 object , archive small, how project doing.
and here error message:
/tmp/cctfdzle.o: in function `main': c2.cpp:(.text+0x5): undefined reference `f()' collect2: ld returned 1 exit status
thanks!
Comments
Post a Comment