【问题标题】:Compiler Error in ptmconvert (C/C++)ptmconvert 中的编译器错误 (C/C++)
【发布时间】:2013-05-03 11:03:07
【问题描述】:

我正在尝试在终端的 mac 上为图像转换器编译一些混合的 C++ 和 C 代码,但遇到了几个错误。成像器转换器代码可在此处获得:

https://code.google.com/p/ptmconvert/

起初,c++ 编译器对有些文件在 c++ 中而有些只是在 c 中这一事实变得很挑剔,我可以使用此处找到的条件定义来解决这个问题:How do I add Objective C code to a FireBreath Project?

也就是说,我只是在主 .cpp 代码导入的 .h 文件周围添加了#ifdef __OBJC__ ... #endif

但是,我仍然从另一个包含中收到两个错误,我无法确定这是同一个问题还是不同的问题。

详细描述包含两个错误和一堆警告:

ptmconvert.cpp:236: error: ‘stbi_load_from_memory’ was not declared in this scope
ptmconvert.cpp:239: error: ‘stbi_failure_reason’ was not declared in this scope

短错误如下:

ptmconvert.cpp:236:25: error: use of undeclared identifier
'stbi_load_from_memory'
            planes[p] = stbi_load_from_memory(reinterpret_cast<unsigned ...
                        ^
ptmconvert.cpp:239:17: error: use of undeclared identifier 'stbi_failure_reason'
            if (stbi_failure_reason())
                ^
ptmconvert.cpp:242:35: error: use of undeclared identifier 'stbi_failure_reason'
                ss << "(stb) " << stbi_failure_reason() << std::endl;
                                   ^
ptmconvert.cpp:326:53: error: use of undeclared identifier 'stbi_image_free'
        std::for_each(planes.begin(), planes.end(), stbi_image_free);
                                                    ^
ptmconvert.cpp:388:10: error: use of undeclared identifier 'stbi_write_png'
    if (!stbi_write_png("coeffH.png", ptm->width, ptm->height, 3, ...
         ^
ptmconvert.cpp:391:10: error: use of undeclared identifier 'stbi_write_png'
    if (!stbi_write_png("coeffL.png", ptm->width, ptm->height, 3, ...
         ^
ptmconvert.cpp:394:10: error: use of undeclared identifier 'stbi_write_png'
    if (!stbi_write_png("rgb.png", ptm->width, ptm->height, 3, &rgbdata[0], 0))
         ^
7 errors generated.

如果是同样的问题,我可以在某处添加另一个条件吗,也许在 stb_image.c 文件中?

好的,所以注释掉包含是愚蠢的。不要那样做,未来的读者。现在我得到的错误是一些术语没有定义:

Undefined symbols for architecture x86_64:
  "_stbi_failure_reason", referenced from:
      ptm_read(char const*, PTMHeader12*) in ptmconvert-g4SsIR.o
  "_stbi_image_free", referenced from:
      ptm_read(char const*, PTMHeader12*) in ptmconvert-g4SsIR.o
  "_stbi_load_from_memory", referenced from:
      ptm_read(char const*, PTMHeader12*) in ptmconvert-g4SsIR.o
ld: symbol(s) not found for architecture x86_64

任何帮助/建议将不胜感激。

【问题讨论】:

  • 尝试将一些对编译器非法的随机字符添加到.h文件中“未声明”函数声明的位置。检查声明是否正确包含。
  • 感谢@MIKU​​_LINK 的建议。它根本没有改变错误。这是否意味着#ifdef __OBJC__ 没有注册objective-c,因此没有导入程序的其他部分?

标签: c++ c macos compiler-errors terminal


【解决方案1】:

好的,所以编译器给出错误的原因是没有 c++ 程序的 makefile。但是,有一个 cmakelists.txt,它向名为 CMake 的 makefile 创建者提供说明:http://www.cmake.org/

要编译 ptmconvert,您需要在 cmakelists.txt 的目录中安装并运行 CMake,这将创建一个 makefile。然后你可以在同一目录下运行 make ,它会创建可执行的 PTM 转换器。

要运行 ptmconverter,只需输入 ./ptmconvert yourPTMfile.ptm

【讨论】:

    猜你喜欢
    • 2013-05-03
    • 2023-03-28
    • 2010-10-25
    • 2012-07-23
    • 1970-01-01
    • 2010-11-24
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多