I'm trying to use Clang on Windows to compile C++ to bitcode and then to an executable (with a view to carrying out some experiments on whole program optimization of the bitcode). When I use clang.exe, even with -D_HAS_EXCEPTIONS=0 -fms-compatibility -fms-extensions, I get errors: main-621e97.o : error LNK2019: unresolved external symbol _Unwind_Resume referenced in function main main-621e97.o : error LNK2001: unresolved external symbol __gxx_personality_v0 main-621e97.o : error LNK2019: unresolved external symbol __cxa_call_unexpected referenced in function "public: class std::_Vector_iterator<class std::_Vector_val<struct std::_Simple_types<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > __cdecl std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::begin(void)" (?begin@?$vector at V?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@ @std@@V?$allocator at V?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@ @std@@@2@@std@@QEAA?AV?$_Vector_iterator at V?$_Vector_val at U?$_Simple_types at V ?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@@std@@@std@ @@2 at XZ) a.out : fatal error LNK1120: 3 unresolved externals clang-cl.exe avoids those errors and can generate an executable from C++, but it doesn't seem to have -emit-llvm or an equivalent option. What am I missing? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150202/50790371/attachment.html>
The references to _Unwind_Resume and __gxx_personality_v0 are surprising, but the rest make sense to me. If you don't need any EH, just pass -fno-exceptions to fix the issue. For more info, read on. :) --- Clang has a few underlying -cc1 exception options: -fexceptions: Indicates the presence of *any* kind of EH. Typically implied by any of the below options. Causes emission of *all* cleanups (C++ dtor, __attribute__((cleanup)), Obj-C @finally, etc) -fcxx-exceptions: Enables C++ try / catch. Makes us use __gxx_personality_v0 etc. -fobjc-exceptions: Enables Obj-C @try / @catch / @finally. Makes us use an Obj-C EH personality. -fsjlj-exceptions: More of a backend option. This changes our EH lowering strategy. clang-cl currently turns on -fexceptions and not -fcxx-exceptions, while clang will enable both by default. Long term, to implement the semantics of MSVC's /EHs, we want to disable C++ dtor cleanups while leaving SEH (__try / __except) enabled. On Mon, Feb 2, 2015 at 8:30 AM, Russell Wallace <russell.wallace at gmail.com> wrote:> I'm trying to use Clang on Windows to compile C++ to bitcode and then to > an executable (with a view to carrying out some experiments on whole > program optimization of the bitcode). > > When I use clang.exe, even with -D_HAS_EXCEPTIONS=0 -fms-compatibility > -fms-extensions, I get errors: > > main-621e97.o : error LNK2019: unresolved external symbol _Unwind_Resume > referenced in function main > main-621e97.o : error LNK2001: unresolved external symbol > __gxx_personality_v0 > main-621e97.o : error LNK2019: unresolved external symbol > __cxa_call_unexpected referenced in function "public: class > std::_Vector_iterator<class std::_Vector_val<struct > std::_Simple_types<class std::basic_string<char,struct > std::char_traits<char>,class std::allocator<char> > > > > __cdecl > std::vector<class std::basic_string<char,struct > std::char_traits<char>,class std::allocator<char> >,class > std::allocator<class std::basic_string<char,struct > std::char_traits<char>,class std::allocator<char> > > >::begin(void)" > (?begin@?$vector at V?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@ > @std@@V?$allocator at V?$basic_string at DU?$char_traits at D@std@@V?$allocator at D > @2@@std@@@2@@std@@QEAA?AV?$_Vector_iterator at V?$_Vector_val at U > ?$_Simple_types at V?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@ > @std@@@std@@@std@@@2 at XZ) > a.out : fatal error LNK1120: 3 unresolved externals > > clang-cl.exe avoids those errors and can generate an executable from C++, > but it doesn't seem to have -emit-llvm or an equivalent option. > > What am I missing? > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150202/fcbaff83/attachment.html>
On Mon, Feb 2, 2015 at 5:59 PM, Reid Kleckner <rnk at google.com> wrote:> The references to _Unwind_Resume and __gxx_personality_v0 are surprising, > but the rest make sense to me. If you don't need any EH, just pass > -fno-exceptions to fix the issue. For more info, read on. :) >That fixed it, thanks!> clang-cl currently turns on -fexceptions and not -fcxx-exceptions, while > clang will enable both by default. Long term, to implement the semantics of > MSVC's /EHs, we want to disable C++ dtor cleanups while leaving SEH (__try > / __except) enabled. >And in the even longer term, implement the /EHsc option? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150202/69da415b/attachment.html>
> > clang-cl.exe avoids those errors and can generate an executable from C++, > but it doesn't seem to have -emit-llvm or an equivalent option. >FYI, you can use this with clang-cl: clang.cl.exe -Xclang -emit-llvm /c ... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150203/64cbcf47/attachment.html>
On 02/02/2015 10:30 AM, Russell Wallace wrote:> I'm trying to use Clang on Windows to compile C++ to bitcode and then > to an executable (with a view to carrying out some experiments on > whole program optimization of the bitcode).If you don't need to use Microsoft back end stuff, I've had good luck with using mingw-64 headers and libraries with clang/LLVM to compile for Windows. I've even used it to compile itself for Windows. clang/LLVM, binutils, and gdb all build just fine. A side benefit is that you can also compile for various Linux targets using the same tool chain on Windows. Binary downloads for both 32 and 64 bit Windows systems and various Linux hosts are available from http://ellcc.org/blog/?page_id=20295 The downloads include pre-built libraries for all the target systems. -Rich