From: Nick W. <nic...@ni...> - 2011-07-07 10:12:18
Attachments:
smime.p7s
|
Environment: MacBook Pro Intel Core Due running Mac OS X Snow Leopard 10.6.7, And 1.8.2 and cpptasks 1.0b5. I have a make file (which I can provide on request) that compiles all of the .cpp files in the directory to .o files then links them as the shared library file librawsockets.jnilib (.jnilib is the Mac extension for .so files that are specific to Java native code ... but it's the same file type). The output when I run this make file is: g++ -Wall -O2 -pipe -D_REENTRANT -I/System/Library/Frameworks/JavaVM.framework/Home/include -c Constants.cpp -o Constants.o g++ -Wall -O2 -pipe -D_REENTRANT -I/System/Library/Frameworks/JavaVM.framework/Home/include -c RawSocketImpl.cpp -o RawSocketImpl.o RawSocketImpl.cpp:216: warning: ‘sockaddr* initIPv4SocketAddress(JNIEnv*, sockaddr_in*, _jbyteArray*)’ defined but not used RawSocketImpl.cpp:230: warning: ‘sockaddr* initIPv6SocketAddress(JNIEnv*, sockaddr_in6*, _jbyteArray*)’ defined but not used g++ -Wall -O2 -pipe -D_REENTRANT -I/System/Library/Frameworks/JavaVM.framework/Home/include -c SocketUtilities.cpp -o SocketUtilities.o g++ -o librawsockets.jnilib Constants.o RawSocketImpl.o SocketUtilities.o -dynamiclib -noprebind -single_module -framework JavaVM ld: warning: option -noprebind is obsolete and being ignored The file is created successfully and all of the native code works with my Java code perfectly. Now, I'm trying to port this to Ant because I'm using Ant to compile my Java code and run my unit tests and I want Ant to do this, too. So here's what I have so far: <cc name="g++" objdir="${rawsockets.dir.output.native}" outtype="shared" runtime="dynamic" rebuild="true" relentless="true" warnings="diagnostic" outfile="librawsockets.jnilib" optimize="full" failonerror="true"> <defineset define="_REENTRANT" /> <includepath path="${jdk.include.1.6}" /> <compilerarg value="-pipe" /> <fileset dir="/Users/Nicholas/RawSocketsNativeSrc" includes="*.cpp" /> <linker name="g++"> <linkerarg value="-noprebind" /> <linkerarg value="-single_module" /> <linkerarg value="-framework" /> <linkerarg value="JavaVM" /> </linker> </cc> And my output is this (it compiles exactly the same but doesn't link): [cc] 3 total files to be compiled. [cc] g++ -pipe -c -O2 -fPIC -D_REENTRANT -W -Wall -I/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp /Users/Nicholas/RawSocketsNativeSrc/Constants.cpp /Users/Nicholas/RawSocketsNativeSrc/SocketUtilities.cpp [cc] /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp:216: warning: ‘sockaddr* initIPv4SocketAddress(JNIEnv*, sockaddr_in*, _jbyteArray*)’ defined but not used [cc] /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp:230: warning: ‘sockaddr* initIPv6SocketAddress(JNIEnv*, sockaddr_in6*, _jbyteArray*)’ defined but not used [cc] Starting link [cc] gcc -Wl,-noprebind -Wl,-single_module -framework JavaVM -prebind -dynamiclib -o liblibrawsockets.jnilib.so out/production/native/RawSocketImpl.o out/production/native/Constants.o out/production/native/SocketUtilities.o [cc] ld: warning: option -noprebind is obsolete and being ignored [cc] Undefined symbols: [cc] "___cxa_rethrow", referenced from: [cc] std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> const&)in Constants.o [cc] "operator new(unsigned long)", referenced from: [cc] std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> const&)in Constants.o [cc] std::vector<_jobject*, std::allocator<_jobject*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<_jobject**, std::vector<_jobject*, std::allocator<_jobject*> > >, _jobject* const&)in SocketUtilities.o (and on and on and on) BUILD FAILED I even tried this: <cc name="g++" objdir="${rawsockets.dir.output.native}" outtype="shared" runtime="dynamic" rebuild="true" relentless="true" warnings="diagnostic" outfile="rawsockets" optimize="full" failonerror="true"> <defineset define="_REENTRANT" /> <includepath path="${jdk.include.1.6}" /> <compilerarg value="-pipe" /> <fileset dir="/Users/Nicholas/RawSocketsNativeSrc" includes="*.cpp" /> <linker name="g++"> <linkerarg value="-single_module" /> <linkerarg value="-framework" /> <linkerarg value="JavaVM" /> </linker> </cc> But I still get this: [cc] 3 total files to be compiled. [cc] g++ -pipe -c -O2 -fPIC -D_REENTRANT -W -Wall -I/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp /Users/Nicholas/RawSocketsNativeSrc/Constants.cpp /Users/Nicholas/RawSocketsNativeSrc/SocketUtilities.cpp [cc] /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp:216: warning: ‘sockaddr* initIPv4SocketAddress(JNIEnv*, sockaddr_in*, _jbyteArray*)’ defined but not used [cc] /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp:230: warning: ‘sockaddr* initIPv6SocketAddress(JNIEnv*, sockaddr_in6*, _jbyteArray*)’ defined but not used [cc] Starting link [cc] gcc -Wl,-single_module -framework JavaVM -prebind -dynamiclib -o librawsockets.so out/production/native/RawSocketImpl.o out/production/native/Constants.o out/production/native/SocketUtilities.o [cc] Undefined symbols: [cc] "___cxa_rethrow", referenced from: [cc] std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> const&)in Constants.o [cc] "operator new(unsigned long)", referenced from: [cc] std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> const&)in Constants.o [cc] std::vector<_jobject*, std::allocator<_jobject*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<_jobject**, std::vector<_jobject*, std::allocator<_jobject*> > >, _jobject* const&)in SocketUtilities.o (and on and on and on) BUILD FAILED I can manually change the name of the .so/.jnilib file, so I'm not worried about that. But why won't this thing link, I wondered? The things that I see are different are the fact that the linker is using gcc (even though the compiler is g++ and I specifically told it to use g++) and that the options -Wl, and -prebind are added. I suspected that gcc was the problem, so I changed my makefile to use gcc to link (but keep using g++ to compile) just like the Ant output and it failed the exact same way, with all of the Undefined symbols errors. Is this a bug that it's mixing the gcc linker with the g++ compiler (and ignoring my request for the g++ linker)? Or am I doing something wrong? Thanks! Nick |
From: Nick W. <nic...@ni...> - 2011-07-07 11:27:51
Attachments:
smime.p7s
|
Follow-up: I did a little more Googling and was reminded about -lstdc++, so I added the following: <linkerarg value="-lstdc++" /> And it works now. Compiles and links perfectly. But my questions still stand: Why does it use g++ to compile and gcc to link when I asked for g++ for both of them? Do I need to file a bug? Or am I doing something wrong? Thanks! Nick On Jul 7, 2011, at 4:44 AM, Nick Williams wrote: > Environment: MacBook Pro Intel Core Due running Mac OS X Snow Leopard 10.6.7, And 1.8.2 and cpptasks 1.0b5. > > I have a make file (which I can provide on request) that compiles all of the .cpp files in the directory to .o files then links them as the shared library file librawsockets.jnilib (.jnilib is the Mac extension for .so files that are specific to Java native code ... but it's the same file type). The output when I run this make file is: > > g++ -Wall -O2 -pipe -D_REENTRANT -I/System/Library/Frameworks/JavaVM.framework/Home/include -c Constants.cpp -o Constants.o > g++ -Wall -O2 -pipe -D_REENTRANT -I/System/Library/Frameworks/JavaVM.framework/Home/include -c RawSocketImpl.cpp -o RawSocketImpl.o > RawSocketImpl.cpp:216: warning: ‘sockaddr* initIPv4SocketAddress(JNIEnv*, sockaddr_in*, _jbyteArray*)’ defined but not used > RawSocketImpl.cpp:230: warning: ‘sockaddr* initIPv6SocketAddress(JNIEnv*, sockaddr_in6*, _jbyteArray*)’ defined but not used > g++ -Wall -O2 -pipe -D_REENTRANT -I/System/Library/Frameworks/JavaVM.framework/Home/include -c SocketUtilities.cpp -o SocketUtilities.o > g++ -o librawsockets.jnilib Constants.o RawSocketImpl.o SocketUtilities.o -dynamiclib -noprebind -single_module -framework JavaVM > ld: warning: option -noprebind is obsolete and being ignored > > The file is created successfully and all of the native code works with my Java code perfectly. Now, I'm trying to port this to Ant because I'm using Ant to compile my Java code and run my unit tests and I want Ant to do this, too. So here's what I have so far: > > <cc name="g++" objdir="${rawsockets.dir.output.native}" outtype="shared" runtime="dynamic" rebuild="true" relentless="true" > warnings="diagnostic" outfile="librawsockets.jnilib" optimize="full" failonerror="true"> > <defineset define="_REENTRANT" /> > <includepath path="${jdk.include.1.6}" /> > <compilerarg value="-pipe" /> > <fileset dir="/Users/Nicholas/RawSocketsNativeSrc" includes="*.cpp" /> > <linker name="g++"> > <linkerarg value="-noprebind" /> > <linkerarg value="-single_module" /> > <linkerarg value="-framework" /> > <linkerarg value="JavaVM" /> > </linker> > </cc> > > And my output is this (it compiles exactly the same but doesn't link): > > [cc] 3 total files to be compiled. > [cc] g++ -pipe -c -O2 -fPIC -D_REENTRANT -W -Wall -I/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp /Users/Nicholas/RawSocketsNativeSrc/Constants.cpp /Users/Nicholas/RawSocketsNativeSrc/SocketUtilities.cpp > [cc] /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp:216: warning: ‘sockaddr* initIPv4SocketAddress(JNIEnv*, sockaddr_in*, _jbyteArray*)’ defined but not used > [cc] /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp:230: warning: ‘sockaddr* initIPv6SocketAddress(JNIEnv*, sockaddr_in6*, _jbyteArray*)’ defined but not used > [cc] Starting link > [cc] gcc -Wl,-noprebind -Wl,-single_module -framework JavaVM -prebind -dynamiclib -o liblibrawsockets.jnilib.so out/production/native/RawSocketImpl.o out/production/native/Constants.o out/production/native/SocketUtilities.o > [cc] ld: warning: option -noprebind is obsolete and being ignored > [cc] Undefined symbols: > [cc] "___cxa_rethrow", referenced from: > [cc] std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> const&)in Constants.o > [cc] "operator new(unsigned long)", referenced from: > [cc] std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> const&)in Constants.o > [cc] std::vector<_jobject*, std::allocator<_jobject*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<_jobject**, std::vector<_jobject*, std::allocator<_jobject*> > >, _jobject* const&)in SocketUtilities.o > (and on and on and on) > BUILD FAILED > > I even tried this: > > <cc name="g++" objdir="${rawsockets.dir.output.native}" outtype="shared" runtime="dynamic" rebuild="true" relentless="true" > warnings="diagnostic" outfile="rawsockets" optimize="full" failonerror="true"> > <defineset define="_REENTRANT" /> > <includepath path="${jdk.include.1.6}" /> > <compilerarg value="-pipe" /> > <fileset dir="/Users/Nicholas/RawSocketsNativeSrc" includes="*.cpp" /> > <linker name="g++"> > <linkerarg value="-single_module" /> > <linkerarg value="-framework" /> > <linkerarg value="JavaVM" /> > </linker> > </cc> > > But I still get this: > > [cc] 3 total files to be compiled. > [cc] g++ -pipe -c -O2 -fPIC -D_REENTRANT -W -Wall -I/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp /Users/Nicholas/RawSocketsNativeSrc/Constants.cpp /Users/Nicholas/RawSocketsNativeSrc/SocketUtilities.cpp > [cc] /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp:216: warning: ‘sockaddr* initIPv4SocketAddress(JNIEnv*, sockaddr_in*, _jbyteArray*)’ defined but not used > [cc] /Users/Nicholas/RawSocketsNativeSrc/RawSocketImpl.cpp:230: warning: ‘sockaddr* initIPv6SocketAddress(JNIEnv*, sockaddr_in6*, _jbyteArray*)’ defined but not used > [cc] Starting link > [cc] gcc -Wl,-single_module -framework JavaVM -prebind -dynamiclib -o librawsockets.so out/production/native/RawSocketImpl.o out/production/native/Constants.o out/production/native/SocketUtilities.o > [cc] Undefined symbols: > [cc] "___cxa_rethrow", referenced from: > [cc] std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> const&)in Constants.o > [cc] "operator new(unsigned long)", referenced from: > [cc] std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> const&)in Constants.o > [cc] std::vector<_jobject*, std::allocator<_jobject*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<_jobject**, std::vector<_jobject*, std::allocator<_jobject*> > >, _jobject* const&)in SocketUtilities.o > (and on and on and on) > BUILD FAILED > > I can manually change the name of the .so/.jnilib file, so I'm not worried about that. But why won't this thing link, I wondered? The things that I see are different are the fact that the linker is using gcc (even though the compiler is g++ and I specifically told it to use g++) and that the options -Wl, and -prebind are added. I suspected that gcc was the problem, so I changed my makefile to use gcc to link (but keep using g++ to compile) just like the Ant output and it failed the exact same way, with all of the Undefined symbols errors. > > Is this a bug that it's mixing the gcc linker with the g++ compiler (and ignoring my request for the g++ linker)? Or am I doing something wrong? > > Thanks! > > Nick |