I'm trying to build a command line tool in C++ using Xcode 11.2.1, and I'm getting stuck trying to configure my dependencies. I'm trying to use a library called libraw
, which I've installed via Homebrew. I see a libraw
directory in /usr/local/include
and a libraw.a/libraw.dylib
in /usr/local/lib
, and I've added those directories in the header search paths and library search paths in the build settings, but when I try to build my project, I get errors about missing symbols from the linker.
Here's my initial test code (for some RAW processing I want to do).
#include "libraw/libraw.h"
int main()
{
// Let us create an image processor
LibRaw iProcessor;
// Open the file and read the metadata
iProcessor.open_file("tether2073.dng");
// The metadata are accessible through data fields of the class
printf("Image size: %d x %d\n",iProcessor.imgdata.sizes.width,iProcessor.imgdata.sizes.height);
// Let us unpack the image
iProcessor.unpack();
// Convert from imgdata.rawdata to imgdata.image:
iProcessor.raw2image();
// And let us print its dump; the data are accessible through data fields of the class
for(int i = 0;i < iProcessor.imgdata.sizes.iwidth * iProcessor.imgdata.sizes.iheight; i++)
printf("i=%d R=%d G=%d B=%d G2=%d\n",
i,
iProcessor.imgdata.image[i][0],
iProcessor.imgdata.image[i][1],
iProcessor.imgdata.image[i][2],
iProcessor.imgdata.image[i][3]
);
// Finally, let us free the image processor for work with the next image
iProcessor.recycle();
return 0;
}
This is the linker invocation:
Ld /Users/<user>/Library/Developer/Xcode/DerivedData/RAWNegativeTool-fwmiuwmyvyuzmtexigwsxnudegjx/Build/Products/Debug/RAWNegativeTool normal x86_64 (in target 'RAWNegativeTool' from project 'RAWNegativeTool')
cd /Users/<user>/Documents/RAWNegativeTool
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.14 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/<user>/Library/Developer/Xcode/DerivedData/RAWNegativeTool-fwmiuwmyvyuzmtexigwsxnudegjx/Build/Products/Debug -L/usr/local/lib -F/Users/<user>/Library/Developer/Xcode/DerivedData/RAWNegativeTool-fwmiuwmyvyuzmtexigwsxnudegjx/Build/Products/Debug -filelist /Users/<user>/Library/Developer/Xcode/DerivedData/RAWNegativeTool-fwmiuwmyvyuzmtexigwsxnudegjx/Build/Intermediates.noindex/RAWNegativeTool.build/Debug/RAWNegativeTool.build/Objects-normal/x86_64/RAWNegativeTool.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/<user>/Library/Developer/Xcode/DerivedData/RAWNegativeTool-fwmiuwmyvyuzmtexigwsxnudegjx/Build/Intermediates.noindex/RAWNegativeTool.build/Debug/RAWNegativeTool.build/Objects-normal/x86_64/RAWNegativeTool_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/<user>/Library/Developer/Xcode/DerivedData/RAWNegativeTool-fwmiuwmyvyuzmtexigwsxnudegjx/Build/Intermediates.noindex/RAWNegativeTool.build/Debug/RAWNegativeTool.build/Objects-normal/x86_64/RAWNegativeTool_dependency_info.dat -o /Users/<user>/Library/Developer/Xcode/DerivedData/RAWNegativeTool-fwmiuwmyvyuzmtexigwsxnudegjx/Build/Products/Debug/RAWNegativeTool
And here are the errors I get when I build:
Undefined symbols for architecture x86_64:
"LibRaw::unpack()", referenced from:
_main in main.o
"LibRaw::recycle()", referenced from:
_main in main.o
"LibRaw::open_file(char const*, long long)", referenced from:
_main in main.o
"LibRaw::raw2image()", referenced from:
_main in main.o
"LibRaw::LibRaw(unsigned int)", referenced from:
_main in main.o
"LibRaw::~LibRaw()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I also attempted to add -l libraw
to the "Other Linker Flags", but I got this error, which indicates that Xcode also can't find my libraries:
ld: library not found for -llibraw
My code is taken directly from the libraw
examples, and those symbols do appear to be defined in /usr/local/include/libraw/libraw.h
so I'm sort of at a loss.