mono / mono

Mono open source ECMA CLI, C# and .NET implementation.
https://www.mono-project.com
Other
11.12k stars 3.82k forks source link

C embedding: libmono-2.0.so: undefined reference to `__cxa_end_catch' #19628

Open lostmsu opened 4 years ago

lostmsu commented 4 years ago

I am following the official embedding doc on compiling and linking.

Here's my .c file:

#include <mono/jit/jit.h>

#define MONO_VERSION "v4.0.30319.1"
#define MONO_DOMAIN "TestDomain"

int main() {
  mono_jit_init_version(MONO_DOMAIN, MONO_VERSION);
  return 0;
}

Steps to Reproduce

gcc testmono.c `pkg-config --libs --cflags mono-2`

Current Behavior

/usr/lib/pkgconfig/../../lib/libmono-2.0.so: undefined reference to `__cxa_end_catch'
/usr/lib/pkgconfig/../../lib/libmono-2.0.so: undefined reference to `typeinfo for int*'
/usr/lib/pkgconfig/../../lib/libmono-2.0.so: undefined reference to `__gxx_personality_v0'
/usr/lib/pkgconfig/../../lib/libmono-2.0.so: undefined reference to `__cxa_begin_catch'
collect2: error: ld returned 1 exit status

Expected Behavior

No error should occur

On which platforms did you notice this

[ ] macOS [x] Linux (Ubuntu 16.04) [ ] Windows

Version Used: 6.8.0.105

GCC Version: 5.4.0

Workaround

Use g++ instead of gcc:

g++ testmono.c `pkg-config --libs --cflags mono-2`
akoeplinger commented 4 years ago

I can't repro on macOS here, which Mono version did you test?

lostmsu commented 4 years ago

@akoeplinger I can not reproduce it on a new macOS VM either, but it might be related to gcc pointing to clang.

Let me remove macOS from repro platforms until I can get instructions for it.

On Ubuntu 16.04 I reproed it just yesterday with build-essential and Mono 6.8.0.105 from the official apt repo.

lostmsu commented 4 years ago

@akoeplinger can't repro on macOS with gcc-9 or gcc-5 from brew. Let's keep it scoped to Ubuntu 16.04 for now.

akoeplinger commented 4 years ago

ok, I guess it's related to how we're building the Linux packages then. @directhex any ideas?

jaykrell commented 4 years ago

Presumably related to any .cpp files, that are there for LLVM interop. It might help to say -fno-exceptions -fno-rtti.

lostmsu commented 4 years ago
$ gcc testmono.c `pkg-config --libs --cflags mono-2` -fno-exceptions -fno-rtti
cc1: warning: command line option ‘-fno-rtti’ is valid for C++/ObjC++ but not for C
/usr/lib/pkgconfig/../../lib/libmono-2.0.so: undefined reference to `__cxa_end_catch'
/usr/lib/pkgconfig/../../lib/libmono-2.0.so: undefined reference to `typeinfo for int*'
/usr/lib/pkgconfig/../../lib/libmono-2.0.so: undefined reference to `__gxx_personality_v0'
/usr/lib/pkgconfig/../../lib/libmono-2.0.so: undefined reference to `__cxa_begin_catch'

Or did you mean those flags should be added to Mono build itself?

akoeplinger commented 4 years ago

Yeah I think we'd need to add that flag to the mono build itself.

lostmsu commented 4 years ago

@akoeplinger not sure it would be useful, but just wanted to remind, that this problem did not affect macOS for some reason on either Clang or GCC, so there seems to be some inconsistency.

LuisAlejandro commented 2 years ago

@akoeplinger hi! I'm having the same error with mono 6.12.0.122, I'm trying to build the latest nightly but I don't know if I have to add any flags to solve this error. Could you clarify it for me? Thanks!

ObamaTheLlama114 commented 1 year ago

I am having this issue as well