Gcc on OS X: Undefined Symbols for x86_64 Architecture

I am writing an application with several subdirectories. I created a Makefile structure so that the subdirectories compile the file and do "ar rvs" and "ranlib libxxx.a" to create archives in the parent directory for linking.

However, the ld command runs in the following problem.

ld: warning: ignoring file ./libxxx.a, file was built for archive which is not the architecture being linked (x86_64): ./libxxx.a Undefined symbols for architecture x86_64: 

I am using gcc on Mac OS X 10.10.1

I read a lot of posts about this. I tried "gcc -arch i386", then I ran into the same error for i386

 Undefined symbols for architecture i386: 

I installed gcc-4.9.2 and tried to use it instead of gcc by default, with no luck. I tried using x86_64-apple-darwin14.0.0-g ++ - 4.9.2, and that didn't help either.

+5
source share
1 answer

The errors you see mean that the assembly has a mixture of i386 and x86_64 code, and you need to be consistent. If you have no good reason (otherwise I would be interested to know what it is), you should compile everything only for 64-bit. Using gcc on a Mac is usually the default, but you can force it to add the -m64 flag to compilation. One way to do this is to set CC="gcc -m64" on the make command line; There are other ways to improve, but the details depend on your makefile content.

To solve: first, delete all the libraries and object code that you created in your project area (perhaps make clean will do this - if you wrote a clean goal). Then set the CC value or its flags ( CFLAGS ultimately, but the way CFLAGS built depends on the makefile ) to ensure 64-bit compilation is performed. Then make sure you use this in all compilations. If you do not see -m64 , you have a problem.

If you must use 32-bit, replace -m32 with -m64 .

The discussion above assumes that you are using gcc to run the ld command. If you do not, you will use it yourself until you use gcc to run the ld command. In my opinion, you have better things to do with your life than working on how to run the ld command correctly; Of course I have.

+1
source

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


All Articles