Question

I have C++ source code in IO.h and IO.cpp and want to make a static library libvcf.a . Then I use the following command:

g++ -c IO.cpp

No problem.

But,

ar -r libvcf.a IO.o

/usr/bin/ranlib: file: libvcf.a(IO.o) has no symbols

I am now using Mac OSX Lion, with g++ versio below:

g++ -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.1~1/src/configure --disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.1~1/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)

It looks like I can use the same commands on Linux, but not on Mac. I also google around and did not have luck. Any suggestions here? Thanks.

Was it helpful?

Solution

I think the full command should be:

ar rcs libvcf.a IO.o

The c means "create archive".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top