简体   繁体   中英

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

I have 32bit 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.

Hopefully I can use -m64 option with the 32bit gcc compiler to achieve this.

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. I found out this is due to the mismatch of 32/64 bit libraries.

The following are the contents of my gcc 32bit lib directory

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? do I need to find their 64 bit equivalent to succcesfully build?

The "-m64" flag tells the compiler to make a 64-bit object. 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. 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.

OK, it's not directly related to your question, but look at downloading and compiling with Oracle's 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. 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.

If you compile your C++ code with "-xport64", you'll probably be shocked at the warnings and errors you see.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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