0

我正在尝试使用 Xcode 11.2.1 在 C++ 中构建命令行工具,但在尝试配置我的依赖项时遇到了困难。我正在尝试使用一个名为 的库libraw,它是通过 Homebrew 安装的。我看到一个librawin/usr/local/include和一个libraw.a/libraw.dylibin目录/usr/local/lib,并且我在构建设置中的标头搜索路径和库搜索路径中添加了这些目录,但是当我尝试构建我的项目时,我收到有关链接器中缺少符号的错误。

这是我的初始测试代码(对于我想做的一些 RAW 处理)。

#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;
}

这是链接器调用:

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

以下是我在构建时遇到的错误:

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)

我还尝试添加-l libraw到“其他链接器标志”,但我收到了这个错误,这表明 Xcode 也找不到我的库:

ld: library not found for -llibraw

我的代码直接取自libraw示例,并且这些符号确实似乎是在其中定义的,/usr/local/include/libraw/libraw.h所以我有点不知所措。

4

0 回答 0