tags:

views:

155

answers:

2

When I try to export the following function as a dll:

extern "C" __declspec(dllexport) void some_func()
{
  throw std::runtime_error("test throwing exception");
}

Visual C++ 2008 gives me the following warning:

1>.\SampleTrainer.cpp(11) : warning C4297: 'some_func' : function assumed not to throw an exception but does
1>        The function is extern "C" and /EHc was specified

I need to extern "C" because I use Qt QLibrary to load the dll and resolve the function name. Without extern "C" it can't find the some_func() function.

A: 

If you are determined to do what the compiler is warning you about, why not just suppress the warning?

#pragma warning(disable: 4247)
John Knoeller
thanks for the advice. However, is there any other way around this? I actually just want to export a C++ function.
ShaChris23
Then don't use extern "C", instead then use a .def file to force the exported name to be the undecorated name (or whatever you want).
John Knoeller
alternatively, you can try and figure out how to get QT to load the C++ decorated name.
John Knoeller
A: 

So I have a related question...

I'm porting a project that has an extern "C", and I get this warning. But the functions in question actually do not throw any errors. I guess the warning comes up /whenever/ one has a c++ function declared as extern "C". Can someone say for sure that it is ok for me to just disable this warning, which would be great. Or I actually need to create a .def file?