c ++ PNG中的未定义引用,但包括png.h

时间:2015-09-23 02:45:39

标签: c++ cmake png homebrew

我正在尝试编译Libviso2。即使包含png.h,也有关于未声明的标识符png的错误。我不确定这里有什么问题?

其中的演示代码类似于

#include <png.h>
...
...
png::image< png::gray_pixel > left_img(left_img_file_name);

我的CMakeLists.txt如下

# project
cmake_minimum_required (VERSION 2.8)
project (libviso2)

find_package(PNG REQUIRED)

# directories
set (LIBVISO2_SRC_DIR src)

# include directory
include_directories(${PNG_INCLUDE_DIRS})
include_directories("${LIBVISO2_SRC_DIR}")

link_directories(${PNG_LIBRARY_DIRS})
add_definitions(${PNG_DEFINITIONS})

# use sse3 instruction set
SET(CMAKE_CXX_FLAGS "-msse3")

# sources
FILE(GLOB LIBVISO2_SRC_FILES "src/*.cpp")

# make release version
set(CMAKE_BUILD_TYPE Release)

# demo program
add_executable(viso2 ${LIBVISO2_SRC_FILES})
target_link_libraries (viso2 ${PNG_LIBRARY})

cmake ../ && make时,它会抛出一堆与找不到的png引用有关的错误

[ 10%] Building CXX object CMakeFiles/viso2.dir/src/demo.cpp.o
/Users/pranav/workspace/libviso2/src/demo.cpp:80:7: error: use of undeclared identifier 'png'
      png::image< png::gray_pixel > left_img(left_img_file_name);
      ^
/Users/pranav/workspace/libviso2/src/demo.cpp:80:19: error: use of undeclared identifier 'png'
      png::image< png::gray_pixel > left_img(left_img_file_name);
                  ^

1 个答案:

答案 0 :(得分:1)

png::命名空间似乎来自C++ bindings to PNGpng++.h头文件。你应该先安装它。

关于CMake代码的一些注释。根据文档,你应该使用target_link_libraries (viso2 ${PNG_LIBRARIES}),你也可以删除link_directories调用,因为CMake会找出所需的标记。