I tried to compile LLVM 2.4 on Mac OS X Lion with this command.
./configure --enable-pic --prefix=/usr/local CC="gcc -arch i386" CXX="g++ -arch i386"
I got this error.
Undefined symbols for architecture i386:
"llvm::PATypeHolder::get() const", referenced from:
llvm::ELFWriter::EmitGlobal(llvm::GlobalVariable*) in libLLVMCodeGen.a(ELFWriter.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
What's wrong with this?
For cross compiling configure likes it when you supply the host, target and build using the machine tuple.
If you're unfamiliar with what your machine tuple is, you can find it using
gcc -dumpmachine
Which, using Lion reports:
i686-apple-darwin11
Note that on Lion x86_64-apple-darwin11 is valid for 64bit.. But, to use that when building llvm:
./configure \
--enable-pic \
--prefix=/usr/local \
--host=i686-apple-darwin11 \
--target=i686-apple-darwin11 \
--build=i686-apple-darwin11
That should do it, but you might want to include
--enable-languages=c,c++,obj-c
--enable-optimized
You can also verify the libraries you're linking against using 'file' and 'otool'. Or, if it's a static archive that you're linking against (which looks to be the case..) my quickie test is
ar p somelib.a $(ar t somelib.a | grep \.o | tail -1) | file -
You're not going to run into an i386 OSX Lion box, so building clang for i386 seems unnecessary - you could probably build the 64 bit version (whatever it chooses by default), and then when you compile WITH that, you would specify '-m32' or '-m64' in your CFLAGS or CXXFLAGS to generate the correct bit depth of objects.
-n
Related
I have a c++ program using opencv libraries. I am able successfully to build my program on MAC OS using dynamic opencv libraries using the following command:
g++ -std=c++11 -Iinclude/ -o detect2 detect2.cpp -Llib3/ \
-lopencv_objdetect \
-lopencv_imgproc \
-lopencv_core \
-lopencv_videoio \
-lopencv_highgui
The above command generates the detect2 executable which works perfectly fine.
However, I want to statically link the opencv libraries so that later I can integrate this program into our MAC app so that we can distribute easliy without asking the user to install opencv on their MAC.
Following is the command I am using to build detect2.cpp using static opencv libs
g++ -std=c++11 -Iinclude/ -o detect2 detect2.cpp \
lib2/libopencv_objdetect.a \
lib2/libopencv_imgproc.a \
lib2/libopencv_core.a \
lib2/libopencv_videoio.a \
lib2/libopencv_highgui.a
But I get the following error:
ld: symbol(s) not found for architecture x86_64 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
If I use -static in the g++ command then I get
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please let me know how can I build my cpp program with static opencv libs on MACOS. Thanks
/usr/bin/ld: i386:x86-64 architecture of input file `build/gengenrtl.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `build/errors.o' is incompatible with i386 output
/usr/bin/ld: build/gengenrtl.o: file class ELFCLASS64 incompatible with ELFCLASS32
/usr/bin/ld: final link failed: File in wrong format
collect2: error: ld returned 1 exit status
I don't get if the problem is ld or the given library.
my configuration is
CC="gcc -m32" \
CFLAGS="-m32" \
LD="<path>/bin/32/binutils/2.23.2/bin/ld" \
LDFLAGS="-m32" \
./configure \
--build=i586-pc-linux-gnu \
--host=i586-pc-linux-gnu \
--target=i586-pc-linux-gnu \
--enable-shared \
--enable-static \
--enable-languages=c,c++ \
--enable-bootstrap \
--prefix=<path>/bin/32/gcc/i586 \
--disable-stage1-checking \
--with-gmp=<path>/lib/32/gmp/5.1.2 \
--with-mpfr=<path>/lib/32/mpfr/3.1.2 \
--with-mpc=<path>/lib/32/mpc/1.0.1 \
--with-cloog=<path>/lib/32/cloog/0.18.0 \
--without-ppl
Apparently I can't change the ld executable so easily, gcc keeps compiling with the global system /usr/bin/ld.
Someone can say what is going on here and how to fix this linking phase ?
I'm under Ubuntu 64 bit and I'm trying to compile a 32 bit build of gcc, of course I have already compiler gmp, mpc, mpfr for 32 bits.
Of course you can build gcc from source as 32-bit, using a 64-bit OS, compiler and linker. The problem is definitely not "ld".
You're doing exactly the right thing: specifying "-m32" in CFLAGS and LDFLAGS.
The problem is that build/gengenrtl.o and build/errors.o appear to have been built for 64-bit (instead of 32-bit).
SUGGESTIONS:
1) Check the makefile, and check your build log. See if there's anything "different" about the build commands for those two files.
2) Use the "nm" command to verify that the rest of your *.o object files were correctly built as 32-bit - that only "gengenrtl.o" and "errors.o" were (incorrectly) built as ELFCLASS64.
'Hope that helps...
I have solved similar problem (Compile gcc on amd64, for running on i686, and target is mips) with adding following to make command line:
CC="gcc -m32" CXX="g++ -m32" LDFLAGS=-m32
No need to specify full path to ld. But you forgot specify which C++ compiler to use.
I have succesfully compiled the LLVM kalidoscope examples in C.
Now I'm extending the code with:
#include "llvm/Support/CommandLine.h"
static cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"), cl::Required);
int mail(...
now i compile using:
clang++ -g toy.cpp llvm-config --cppflags --ldflags --libs all -O3 -o toy
and after this change i receive the following error:
Undefined symbols for architecture x86_64:
"typeinfo for llvm::cl::GenericOptionValue", referenced from:
typeinfo for llvm::cl::OptionValueCopy<std::string> in toy-Pq1GSI.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What could be wrong, and how can i fix it?
Versions:
clang++ -v Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.2.0 Thread model: posix
brew info llvm llvm: stable 3.2 (bottled), HEAD http://llvm.org/ /usr/local/Cellar/llvm/3.2 (628 files, 106M) * https://github.com/mxcl/homebrew/commits/master/Library/Formula/llvm.rb
==> Options
--all-targets Build all target backends
--universal Build a universal binary
--rtti Build with C++ RTTI
--shared Build LLVM as a shared library
--with-clang Build Clang C/ObjC/C++ frontend
==> Caveats Extra tools and bindings are installed in /usr/local/Cellar/llvm/3.2/share/llvm and /usr/local/Cellar/llvm/3.2/share/clang.
It seems that changing the compile command to this is a fix:
clang++ -g toy.cpp llvm-config --cxxflags --ldflags --libs -O3 -o toy
I'm trying to make dynamic lib from set of .o files, but when i do
gcc -dynamiclib -current_version 1.0 mymod.o -o mylib.dylib
or
ld *.o -o mylib.dylib
i get a lot of errors like:
"_objc_msgSend", referenced from:
-[NSObject(NSObject_SBJSON) JSONFragment] in NSObject+SBJSON.o
"operator new(unsigned long)", referenced from:
MStatistic::instance() in MStatistic.o
StatisticProfileLoggingObserver::instance() in StatisticObserver.o
ld: symbol(s) not found for architecture x86_64
Can you please help me, how to solve it and get my .dylib?
You can pass -undefined dynamic_lookup as an option to ld, or:
-Wl,-undefined -Wl,dynamic_lookup to gcc or clang (which passes it to the linker).
From this line:
ld: symbol(s) not found for architecture x86_64
it sounds like you are building some libraries that have make files that only build for 32-bit architectures.
You need to modify the makefiles for all the libraries / frameworks you're building to build both 32-bit and 64-bit; and in a practical sense, all shipping MacOS machines are 64-bit capable so it may just be safe to build only for 64-bit.
In your compile / linking lines, add something like this: "-arch x86_64" and that should compile things for the 64-bit side. To do both 32 & 64-bit, you'll basically need to duplicate the compile & link lines with their own "-arch i386" and "-arch x86_64" lines.
I'm trying to install the Haskell regex-pcre library using:
cabal install --extra-include-dirs=/usr/local/include \
--extra-include-dirs=/usr/include regex-pcre
However I get this weird error:
Resolving dependencies...
Configuring regex-pcre-0.94.2...
Preprocessing library regex-pcre-0.94.2...
In file included from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include/HsFFI.h:68,
from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/template-hsc.h:4,
from dist/build/Text/Regex/PCRE/Wrap_hsc_make.c:1:
/usr/include/float.h:8:24: error: float.h: No such file or directory
In file included from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/template-hsc.h:9,
from dist/build/Text/Regex/PCRE/Wrap_hsc_make.c:1:
/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
compiling dist/build/Text/Regex/PCRE/Wrap_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/build/Text/Regex/PCRE/Wrap_hsc_make.c -o dist/build/Text/Regex/PCRE/Wrap_hsc_make.o -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -D__GLASGOW_HASKELL__=700 -Ddarwin_BUILD_OS -Ddarwin_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -I/usr/include -I/usr/local/include -DHAVE_PCRE_H -DSPLIT_BASE=1 -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/bytestring-0.9.1.10/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/base-4.3.1.0/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include/
cabal: Error: some packages failed to install:
regex-pcre-0.94.2 failed during the building phase. The exception was:
ExitFailure 1
The gist of it, seems to be that it can't find a second float.h file:
/usr/include/float.h:8:24: error: float.h: No such file or directory
I've opened /usr/include/float.h and line 8 reads:
#include_next <float.h>
I've done my searching on Google, and although I don't know that much C I think I understand what that line is supposed to say, but... I don't know how to really solve this problem. I don't know where else I have a float.h file on my system.
The GHC and GCC versions I'm using. GCC comes from XCode 4. GHC is 32bit, but I've tried the 64bit version too, with the same results.
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.2
OS X version is 10.6.7.
Any help greatly appreciated.
Looks to me like ticket #5011 - XCode 4 on Mac + GHC 7.0.2 fails to link.
This is fixed in GHC 7.0.3 which will be part of the mid-April release of the Haskell Platform.
And alternative fix is to downgrade to the 2010.2 Haskell Platform.
See this question yesterday: Can't install OpenGLRaw-1.1.0.1 on OS X