Originally Posted by
Salem
If you do the same "nm" on main.o, you should see the Timer:: methods it's looking for.
nm says that the library has the symbols that main.o is looking for
Originally Posted by
Salem
Also try say
g++ -M prog.cpp
as well.
The -M option lists all the dependencies (as makefile rules).
Are you getting the Timer.h you think you're supposed to be getting?
It's getting the correct Timer.h
Originally Posted by
whoie
I'm trying to build your OS X tarball, and I built your libraries fine and installed them.
When I go to make exec, I can't get past the 64-bit library stuff which I seem to be missing:
When I tried removing th -m64 option from your makefiles, I get crazy errors that _main symbol is not found. I could never get the Timer lib to go missing though. The linker probably never gets far enough to check that.
Have you tried a g++ -print-search-dirs to see if your library search path includes /usr/lib?
It includes /usr/lib, but not /usr/local/lib. Do you know how I can add that to the path? (It's not what's causing the error because the library used to be in /usr/lib tho)
I did get this to work:
I'm thinking either your path is wrong, or something in your program is killing the build process and you are just getting a weird linking error from it.
I wish I could help further, this sounds like a real frustrating problem.
Still nothing on my end . You've helped my knowledge a lot, even if I still can't get the damned thing to link
Originally Posted by
arpsmack
That's an interesting point. Why don't you try putting all your files in the same directory and building your main file with the command:
g++ -m64 -O2 -o exec -I. -L. main.cpp -framework OpenGL -framework GLUT -lThreading -lUtil
You'll see whether its a path issue or not at least.
Still nothing.
Code:
$ ls
libUtil.a main.cpp
$ cat main.cpp
#include <iostream>
#include <Timer.h>
using std::cout;
using std::cin;
using std::endl;
int main(int argc, char **argv){
char c;
unsigned long usec = 0;
Timer t;
for( t.start(); cin.get(c); t.reset() ) {
usec = t.getMicroSeconds();
cout << "Time elapsed: " << usec << " usecs." << endl;
}
return 0;
}
$ g++ -L. -o main main.cpp -lUtil
Undefined symbols:
"Timer::~Timer()", referenced from:
_main in ccHp0mMQ.o
_main in ccHp0mMQ.o
"Timer::Timer()", referenced from:
_main in ccHp0mMQ.o
"Timer::start()", referenced from:
_main in ccHp0mMQ.o
"Timer::reset()", referenced from:
_main in ccHp0mMQ.o
"Timer::getMicroSeconds()", referenced from:
_main in ccHp0mMQ.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I guess it has to be a problem with the library, it's in the same directory so it isn't a problem of finding it. Here's what nm gives me tho
Code:
$nm main.o
000001f8 s EH_frame1
0000014f s GCC_except_table0
000001e0 s __GLOBAL__I_main
000002a0 s __GLOBAL__I_main.eh
U __Unwind_Resume
00000188 s __Z41__static_initialization_and_destruction_0ii
00000274 s __Z41__static_initialization_and_destruction_0ii.eh
U __ZN5Timer15getMicroSecondsEv
U __ZN5Timer5resetEv
U __ZN5Timer5startEv
U __ZN5TimerC1Ev
U __ZN5TimerD1Ev
U __ZNKSt9basic_iosIcSt11char_traitsIcEEcvPvEv
U __ZNSi3getERc
U __ZNSolsEPFRSoS_E
U __ZNSolsEm
U __ZNSt8ios_base4InitC1Ev
U __ZNSt8ios_base4InitD1Ev
U __ZSt3cin
U __ZSt4cout
U __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
00000322 b __ZSt8__ioinit
U __ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
U ___cxa_atexit
U ___dso_handle
U ___gxx_personality_v0
00000110 t ___tcf_0
00000248 s ___tcf_0.eh
00000000 T _main
00000218 S _main.eh
$ nm libUtil.a
libUtil.a(Timer.o):
0000000000000178 s EH_frame1
0000000000000160 s __GLOBAL__I__ZN5TimerC2Ev
0000000000000348 s __GLOBAL__I__ZN5TimerC2Ev.eh
0000000000000110 s __Z41__static_initialization_and_destruction_0ii
0000000000000318 s __Z41__static_initialization_and_destruction_0ii.eh
00000000000000b0 T __ZN5Timer15getMicroSecondsEv
00000000000002b8 S __ZN5Timer15getMicroSecondsEv.eh
0000000000000080 T __ZN5Timer5resetEv
0000000000000288 S __ZN5Timer5resetEv.eh
0000000000000050 T __ZN5Timer5startEv
0000000000000258 S __ZN5Timer5startEv.eh
0000000000000020 T __ZN5TimerC1Ev
00000000000001c8 S __ZN5TimerC1Ev.eh
0000000000000000 T __ZN5TimerC2Ev
0000000000000198 S __ZN5TimerC2Ev.eh
0000000000000040 T __ZN5TimerD1Ev
0000000000000228 S __ZN5TimerD1Ev.eh
0000000000000030 T __ZN5TimerD2Ev
00000000000001f8 S __ZN5TimerD2Ev.eh
U __ZNSt8ios_base4InitC1Ev
U __ZNSt8ios_base4InitD1Ev
0000000000000378 b __ZSt8__ioinit
U ___cxa_atexit
U ___dso_handle
U ___gxx_personality_v0
00000000000000f0 t ___tcf_0
00000000000002e8 s ___tcf_0.eh
U _gettimeofday
Also, check here:
Mac LD Man Page. Look under the section named "Options for introspecting the linker". Try passing the linker the "-t" flag.
Thanks for the link. I don't think I'm invoking ld correctly (I've never linked without gcc/g++'s interface) since it can't find what looks like some iostream related symbols
Code:
$ ls
libUtil.a main.cpp
$ g++ -m64 -c main.cpp
$ ld main.o -L. -t
main.o
Undefined symbols:
"__ZNSolsEm", referenced from:
_main in main.o
"___gxx_personality_v0", referenced from:
EH_frame1 in main.o
"__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_", referenced from:
_main in main.o
"__ZN5TimerD1Ev", referenced from:
_main in main.o
_main in main.o
"__ZNSt8ios_base4InitD1Ev", referenced from:
___tcf_0 in main.o
"__ZNSolsEPFRSoS_E", referenced from:
_main in main.o
"__ZNSi3getERc", referenced from:
_main in main.o
"___cxa_atexit", referenced from:
__Z41__static_initialization_and_destruction_0ii in main.o
"__ZNKSt9basic_iosIcSt11char_traitsIcEEcvPvEv", referenced from:
_main in main.o
"__ZN5TimerC1Ev", referenced from:
_main in main.o
"__ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc", referenced from:
_main in main.o
_main in main.o
"__ZNSt8ios_base4InitC1Ev", referenced from:
__Z41__static_initialization_and_destruction_0ii in main.o
"__ZN5Timer5startEv", referenced from:
_main in main.o
"__ZN5Timer5resetEv", referenced from:
_main in main.o
"__Unwind_Resume", referenced from:
_main in main.o
"__ZSt3cin", referenced from:
_main in main.o
"__ZN5Timer15getMicroSecondsEv", referenced from:
_main in main.o
"__ZSt4cout", referenced from:
_main in main.o
ld: symbol(s) not found for inferred architecture x86_64
Thanks for all the help guys. Just when I thought I understood linking...
These two archives contain the simple program I'm working with now and the Timer files. Nothing is 64 bit and no non-standard headers are required. Here is the output of make for me
Code:
$ make
g++ -ansi -W -Wall -c Timer.cpp
a - Timer.o
g++ -ansi -W -Wall -c main.cpp
main.cpp:8: warning: unused parameter ‘argc’
main.cpp:8: warning: unused parameter ‘argv’
g++ -ansi -W -Wall -o main -L. -I. main.o -lUtil
Undefined symbols:
"Timer::~Timer()", referenced from:
_main in main.o
_main in main.o
"Timer::Timer()", referenced from:
_main in main.o
"Timer::start()", referenced from:
_main in main.o
"Timer::reset()", referenced from:
_main in main.o
"Timer::getMicroSeconds()", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [all] Error 1
Zip File
Tarball