How can I compile boost using the __cdecl calling convention?

I have a project compiled using the __cdecl calling __cdecl (msvc2010), and I compiled boost using the same compiler using the default settings.

A project related to boost, but I, at runtime, received a message with an approval like this: File: ... \ boost \ boost \ program_options \ detail \ parsers.hpp Line: 79

Runtime Check Error # 0 - ESP value was not properly stored during function call. This is usually the result of calling a function declared with one call, with a function pointer declared with another calling convention.

The following questions arise:

  • that the calling convention increases the default build in Windows (msvc2010)
  • how to compile boost using __cdecl calling convention
  • Why wasn't boost able to prevent code linking with various calling conventions? I realized that boost has really smart code to automatically enable the library.

Update # 1

It looks like boost is compiling and linking to the corresponding calling convention, but at runtime I get the above problem. I made an example application using the same code and it works, but it fails in my application. The only difference may be from the project configuration or includes / stdafx.h

0
source share
3 answers

I found the cause of the problem in one of the common properties files: <StructMemberAlignment>4Bytes</StructMemberAlignment>

If I remove it, the code will work. However, I am not sure why this is happening and how I can solve it without deleting the above code (which was required by another library).

I added another question regarding the elevation and alignment of structural elements .

0
source

As far as I know, there is no way to force C ++ to use the cdecl calling conventions (see the MSDN Calling Convention ). The call to the C ++ method is simply different from C. The only way you should use one of the conventions for calling C is with functions that include the static functions of a C ++ class. If you know that case, you can try to force the parameter at creation by adding the parameter at build time:

bjam cxxflags = / Gd ...

(see BBv2 Built-in Functions )

Or, to make it β€œpersistent,” configure user-config.jam with your compiler and add it to the build options for all BBv2-msvc collections (see BBv2 Configuration and related documents). Regarding other issues:

  • Boost uses the standard MSVC calling convention unless it overrides it at the code level. I do not know where they are, since they are library specific. Therefore, you will have to look for code for code decorators "__ *".
  • See above for a partial answer.
  • Detection; There are two reasons: there is a limit to how many different options we can reasonably determine for construction, since this is an exponential growth of various possible variations, so we limit it to the most important cases. And in the case of calling an agreement, this is actually impossible, since it can be changed based on each function.
+1
source

Just use

 bjam ... **cxxflags=/Zp4** 

when creating additional libraries.

+1
source

Source: https://habr.com/ru/post/1307994/


All Articles