8

I did some search, all answers seem to suggest that using clang++ instead of clang (or rather g++ in place of gcc), which is what I did in the first place. Still, the problem persists, with either

clang++ -Wall -std=c++11 -o test.exe test.cpp A.cpp B.cpp etc.cpp

or

clang++ -lstdc++ -Wall -std=c++11 -o test.exe test.cpp A.cpp B.cpp etc.cpp

The compilation and linking works fine with g++ in Cygwin.

g++ -Wall -std=c++11 -o test.exe test.cpp A.cpp B.cpp etc.cpp

Update:

Here is the information during linking. Is clang trying to use gcc for linking, rather than g++? In that case, why didn't flag -lstdc++ and the -lsupc++ as suggested below, work?

COMPILER_PATH=/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/:/usr/lib/gcc/x86_64-pc-cygwin/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/:/usr/lib/gcc/x86_64-pc-cygwin/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/lib/../lib/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/lib/:/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-m64' '-o' 'testReSampling.exe' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/collect2.exe --build-id -m i386pep --wrap _Znwm --wrap _Znam --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwmRKSt9nothrow_t --wrap _ZnamRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=cyg --tsaware -o testReSampling.exe /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/crt0.o /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/crtbegin.o -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3 -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/lib -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../.. -lsupc++ /tmp/misc-8020e8.o /tmp/DataStruct-b10944.o /tmp/HyperGeometricPVal-edef1c.o /tmp/Array2EG-3441bb.o /tmp/GOCats-ff22c1.o /tmp/UGraph-10cfd8.o /tmp/testReSampling-9fb18c.o -lstdc++ -lgcc_s -lgcc -lcygwin -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/default-manifest.o /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/crtend.o
/tmp/misc-8020e8.o:fake:(.eh_frame+0x47): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISsSaISsEE5clearEv+0x13): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISt4pairIjS0_ItdEESaIS2_EE5beginEv+0x13): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISt4pairIjS0_ItdEESaIS2_EE3endEv+0x13): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISt4pairIjS0_ItSt5arrayIdLm2EEEESaIS4_EE5beginEv+0x13): undefined reference to `__gxx_personality_v0'
/tmp/misc-8020e8.o:fake:(.eh_frame$_ZNSt6vectorISt4pairIjS0_ItSt5arrayIdLm2EEEESaIS4_EE3endEv+0x13): more undefined references to `__gxx_personality_v0' follow
collect2: error: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
CloudyTrees
  • 711
  • 2
  • 10
  • 20

3 Answers3

6

Found this solution:

https://cygwin.com/ml/cygwin/2015-06/msg00294.html

Basically just add -fno-exceptions on the command line when you compile for example clang++ helloworld.cpp -std=c++11 -fno-exceptions

user18490
  • 3,546
  • 4
  • 33
  • 52
2

OK, as I was further wandering around the web, I found a relevant post, see nos's answer.

So I realized I was compiling with Cygwin64 terminal, while Cygwin's clang port is a 32 version. After switching to the Cygwin32 terminal, everything works fine.

Community
  • 1
  • 1
CloudyTrees
  • 711
  • 2
  • 10
  • 20
  • Is 64bit clang supported on Cygwin now? – CMCDragonkai Jul 12 '15 at 02:21
  • @CMCDragonkai, I've been using clang64 in Cygwin exclusively for catching errors (I make heavy use of templates so the colored error messages are much helpful), but unfortunately, never used to generate binaries. The reason being that the gxx_personality_v0 thing is related to how clang handle exceptions, and clang's way doesn't seem to be compatible with the way Windows handle them. – CloudyTrees Jul 12 '15 at 02:27
  • I just tried clang/llvm stuff on 64bit cygwin, and kept hitting things like `gxx_personality` and `linker` errors because it uses gcc to do linking for some reason. – CMCDragonkai Jul 12 '15 at 02:31
  • @CMCDragonkai, yes, those are the errors that I got. Generally, if no exceptions are involved, and if you explicit disable the handling of exceptions in the clang's flag when you compile, things work (which isn't an option for me because I need to use exceptions). – CloudyTrees Jul 12 '15 at 02:34
  • @CMCDragonkai, One other point, someone has successfully built clang and llvm from source under windows using MSVC and/or MingW, but I didn't succeed because of some weird built in math functions from gcc in MingW (which is too bad too since I do number crunching). http://stackoverflow.com/questions/9427356/how-to-compile-clang-on-windows – CloudyTrees Jul 12 '15 at 02:37
0

Try: clang++ -fno-exceptions -Xclang -fcxx-exceptions or clang++ -Xclang -fseh-exceptions

zzh
  • 1
  • 2