简体   繁体   English

使用gcc 32位作为-m64的64位程序进行编译

[英]compiling using gcc 32bit, as a 64 bit program with -m64

I have 32bit gcc. 我有32位的gcc。 Since all my third party libraries are 64 bit, and due to the project contraints, I will have to build my applications in to 64 bit in solaris. 由于我所有的第三方库都是64位的,并且由于项目的限制,我将不得不在solaris的64位中构建我的应用程序。

Hopefully I can use -m64 option with the 32bit gcc compiler to achieve this. 希望我可以在32位gcc编译器中使用-m64选项来实现此目的。

But I'm not sure if this alone would suffice to successfully build. 但是我不确定仅此一项是否足以成功构建。

I repeatedly get wrong ELF class: ELFCLASS64 errors even if I use -m64 for the 32bit compiler. 我反复得到wrong ELF class: ELFCLASS64即使对于32位编译器使用-m64, wrong ELF class: ELFCLASS64错误也是如此。 I found out this is due to the mismatch of 32/64 bit libraries. 我发现这是由于32/64位库的不匹配。

The following are the contents of my gcc 32bit lib directory 以下是我的gcc 32位lib目录的内容

ls -ltr /xxx/xxx/gcc/32-bit/4.4.1/lib/

   4096 Aug 17  2009 gcc
    894 Aug 17  2009 libsupc++.la
 574980 Aug 17  2009 libsupc++.a
5670284 Aug 17  2009 libstdc++.so.6.0.12
    960 Aug 17  2009 libstdc++.la
7507622 Aug 17  2009 libstdc++.a
   4096 Aug 17  2009 debug
  26504 Aug 17  2009 libssp.so.0.0.0
    933 Aug 17  2009 libssp.la
  44866 Aug 17  2009 libssp.a
    915 Aug 17  2009 libssp_nonshared.la
   2402 Aug 17  2009 libssp_nonshared.a
 228812 Aug 17  2009 libgcc_s.so.1
3081544 Aug 17  2009 libgfortran.so.3.0.0
    972 Aug 17  2009 libgfortran.la
4360794 Aug 17  2009 libgfortran.a
 611750 Aug 17  2009 libiberty.a
   4096 Aug 17  2009 amd64
    170 Aug 17  2009 libgomp.spec
 247908 Aug 17  2009 libgomp.so.1.0.0
    945 Aug 17  2009 libgomp.la
 333476 Aug 17  2009 libgomp.a
     13 Aug 17  2009 libgcc_s.so -> libgcc_s.so.1
     20 Aug 17  2009 libgfortran.so -> libgfortran.so.3.0.0
     20 Aug 17  2009 libgfortran.so.3 -> libgfortran.so.3.0.0
     16 Aug 17  2009 libgomp.so -> libgomp.so.1.0.0
     16 Aug 17  2009 libgomp.so.1 -> libgomp.so.1.0.0
     15 Aug 17  2009 libssp.so -> libssp.so.0.0.0
     15 Aug 17  2009 libssp.so.0 -> libssp.so.0.0.0
     19 Aug 17  2009 libstdc++.so -> libstdc++.so.6.0.12
     19 Aug 17  2009 libstdc++.so.6 -> libstdc++.so.6.0.12

All these C++ libraries are 32 bit isnt it? 所有这些C ++库都是32位的吗? do I need to find their 64 bit equivalent to succcesfully build? 我是否需要找到它们的64位等效项才能成功构建?

The "-m64" flag tells the compiler to make a 64-bit object. “ -m64”标志告诉编译器创建一个64位对象。 You need the 64-bit libraries for a 64-bit binary no matter what the ELF class of the compiler that makes your binary is. 无论使二进制文件的编译器的ELF类是什么,都需要64位二进制文​​件的64位库。 What's the full path to the libraries that are giving you the errors? 出现错误的库的完整路径是什么? It's likely you'll need to change some compiler/linker arguments and/or environment variables to pick up the correct 64-bit libraries. 您可能需要更改一些编译器/链接器参数和/或环境变量才能使用正确的64位库。

OK, it's not directly related to your question, but look at downloading and compiling with Oracle's Solaris Studio. 好的,这与您的问题没有直接关系,但是请考虑使用Oracle的Solaris Studio下载和编译。

The Studio C++ compiler has an "-xport64" option that's really good at detecting problems with 64-bit code, especially code written by developers so used to the 32-bit ILP32 model that they do things like stuff pointer or size_t values into int variables without thinking. Studio C ++编译器具有“ -xport64”选项,该选项非常擅长检测64位代码的问题,尤其是开发人员编写的代码,这种代码习惯了32位ILP32模型,可将诸如填充指针或size_t值等内容转换为int变量想都没想。 There's no real easy way that I'm aware of to get GCC to emit a set of just 64-bit related programming errors/warnings. 我知道没有真正简单的方法可以使GCC发出一组仅与64位相关的编程错误/警告。

If you compile your C++ code with "-xport64", you'll probably be shocked at the warnings and errors you see. 如果使用“ -xport64”编译C ++代码,您可能会对看到的警告和错误感到震惊。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM