0

I've seen many following references: command to compile c files with .a files

I have a .cpp file I am trying to compile. I have in addition to this the .h file and 2 .a files.

g++ 1_SDKinfo.cpp -L. -l l* -o a.out -v

g++ 1_SDKinfo.cpp -L ../Lib/mac32_64 -lR3DSDK -lR3dSDKllvm -o a.out -v

I've tried many variants of this, but keep getting errors like

ld: library not found for -llibR3DSDK.a

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Directory of Files

1_SDKinfo.cpp       R3DSDKDecoder.h     R3DSDKOpenCL.h      REDCuda.dylib       REDR3D.dylib
R3DSDK.h        R3DSDKDefinitions.h R3DSDKRocket.h      REDDecoder.dylib    libR3DSDK.a
R3DSDKCuda.h        R3DSDKMetadata.h    R3DSDKStream.h      REDOpenCL.dylib     libR3DSDKllvm.a

How exactly am I supposed to compile this? edit: mac os

John Lippson
  • 1,269
  • 5
  • 17
  • 36
  • If this is a case sensitive filesystem then `-lR3dSDKllvm` will not find `libR3DSDKllvm.a` because of the different case. You need `-lR3DSDKllvm` – Galik Nov 06 '17 at 00:23

1 Answers1

0

Well first of all the library you want to link with is in the current directory (it seems) so you should be using . as the argument to -L, to add the current directory to the library search path.

The second problem is that the name of a library is not the same as the file name. For a file named like libR3DSDK.a the library name is R3DSDK. The linker automatically adds the lib prefix and .a suffix.

So your command should be like

g++ 1_SDKinfo.cpp -L. -lR3DSDK -o a.out -v

Or

g++ 1_SDKinfo.cpp libR3DSDK.a -o a.out -v

The first command uses the -L and -l options to name the library, and the path where to find it. The second command doesn't use any special options, but instead list the file to link with.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Seem to be getting ld: symbol(s) not found for architecture x86_64 – John Lippson Nov 06 '17 at 00:37
  • @RyanHack That's another problem for another question (which most likely will be closed as a duplicate of [this question](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix)), and probably means you forgot to link with some library. – Some programmer dude Nov 06 '17 at 08:52