change _cdecl for Win32 switch to x64

Hi,

I wrote a program based on Win32. Now I need to switch it to x64 to be capable to take benefit of x64's computing power. During the switch, there is one thing blocked: some third-part library uses cdecl that cannot be used on x64 anymore. So it cannot compile.

I remember the cdecl is related to calling convention. Please, does anyone know how to fix it so I can run on x64? Thanks!
Last edited on
Any idea, please?
Last edited on
please...
What compiler do you use ? With Microsoft Visual Studio On Itanium Processor Family (IPF) and x64 processors, __cdecl is accepted and ignored by the compiler;

http://msdn.microsoft.com/en-us/library/zkwh89ks.aspx
http://en.wikipedia.org/wiki/X86_calling_conventions
Right in the beginning of every translation unit, have

1
2
3
#ifdef _M_IA64
    #define __cdecl
#endif // _M_IA64 


Or, alternatively, compile with the preprocessor definition:

/D__cdecl=
See http://msdn.microsoft.com/en-us/library/hhzbb5c8.aspx
Thanks for your replies. I use VC 2012. But I am not sure about the point related to
Itanium Processor Family
, my CPU is a "i5".

If I understand correctly, the definition
#ifdef _M_IA64
#define __cdecl
#endif // _M_IA64

means to force the x64 compiler to use _cdecl? But I read some articles which explain that VC x64 compiler does not support _cdecl anymore.

What is a translation unit? I am confused. Could someone please help me out?
Last edited on
any idea please?
> If I understand correctly, the definition
1
2
3
> #ifdef _M_IA64
> #define __cdecl
> #endif // _M_IA64 

> means to force the x64 compiler to use _cdecl?

No, it means strip all __cdecl from the translation unit. That is, replace int __cdecl foo(double) with int foo(double)


> What is a translation unit?

A simplified definition would be: every file on which you invoke the C++ compiler driver, with the #includes being expanded.


In short, just knock off all occurrences of __cdecl from all files. Then re-compile and re-link everything - the libraries and your program.
Thanks for the reply. I have tried with the
_M_IA64
command but it did not work.

Here is the errors indicated by the compiler while I switch from win32 to x64 debug. Always the same.
1
2
3
4
5
6
7
1>27-9_main.obj : error LNK2019: unresolved external symbol "public: void __cdecl boost::iostreams::file_descriptor::close(void)" ...
1>27-9_main.obj : error LNK2019: unresolved external symbol "public: __int64 __cdecl boost::iostreams::file_descriptor::write(char const *,__int64)" ...
1>27-9_main.obj : error LNK2019: unresolved external symbol "public: class std::fpos<int> __cdecl boost::iostreams::file_descriptor::seek(__int64,int)" ...
1>27-9_main.obj : error LNK2019: unresolved external symbol "public: __cdecl boost::iostreams::file_descriptor_sink::file_descriptor_sink(int,enum boost::iostreams::file_descriptor_flags)" ...
1>27-9_main.obj : error LNK2019: unresolved external symbol "public: __cdecl boost::iostreams::file_descriptor_sink::file_descriptor_sink(class boost::iostreams::file_descriptor_sink const &)" ...
1>27-9_main.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" ...
1>27-9_main.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" ...

If I am right, is it related to the _cdecl in boost::iostreams and system?
Last edited on
> If I am right, is it related to the _cdecl in boost::iostreams and system?

Yes.

You need to rebuild all your libraries for a 64 bit platform with the __cdecl removed. And then you need to have the preprocessor defines before you include any header which was written for a 32 bit platform.
Do you mean in this case to rebuild boost libraries for x64 ?
No, because obviously boost is not part of "all your libraries".
Last edited on
Well actually I use an external header which includes some boost libraries. While the conversion of my program to x64, the related boost libraries stop the compilation, as I showed above. My own code is ok when I convert to x64 debug. That is why I think I have to rebuild boost for x64.

Am I right?
Yes, you need to rebuild boost for 64-bit, I was hoping the sarcasm in my previous post would give you a laugh. I guess I shouldn't push my luck with plain-text.
Oh, it's ok, no harm.

I already have checked about building boost 1.53 for 64bit. I didn't find an clear instruction to build it. There is a installer for win64, but it occupies 8 Go which is huge. I prefer to build it by myself. Any idea about build it for VC11? Building on 32bit is quite simple but there should be some difference between them.
Topic archived. No new replies allowed.