QtCreator with C 库中的链接器问题
Linker problem in QtCreator with C library
我有一个具有以下结构的项目:
3rd_party
- heatmap.c
- heatmap.h
- lodepng.cpp
- lodepng.h
CMakeLists.txt
data.cpp
data.hpp
main.cpp
运行项目时出现以下错误:
error: Undefined symbols for architecture x86_64:
"_heatmap_add_weighted_point", referenced from:
Data::plotImage(int, int, std::__1::vector<short, std::__1::allocator<short> > const&, std::__1::vector<Spherical, std::__1::allocator<Spherical> > const&, int) in data.cpp.o
"_heatmap_free", referenced from:
Data::plotImage(int, int, std::__1::vector<short, std::__1::allocator<short> > const&, std::__1::vector<Spherical, std::__1::allocator<Spherical> > const&, int) in data.cpp.o
"_heatmap_new", referenced from:
Data::plotImage(int, int, std::__1::vector<short, std::__1::allocator<short> > const&, std::__1::vector<Spherical, std::__1::allocator<Spherical> > const&, int) in data.cpp.o
"_heatmap_render_default_to", referenced from:
Data::plotImage(int, int, std::__1::vector<short, std::__1::allocator<short> > const&, std::__1::vector<Spherical, std::__1::allocator<Spherical> > const&, int) in data.cpp.o
我data.cpp
的一部分是:
#include "data.hpp"
#include <fstream>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <array>
#include "3rd_party/heatmap.h"
/**
* Create the heatmap PNG file, suing the package in https://github.com/lucasb-eyer/libheatmap
* @param Nx Number of columns of data.
* @param Ny Number of rows of data.
* @param image Array with the data to be converted to PNG.
* @param counter To be included in the filename to distinguish between pictures.
*/
void Data::plotImage(int Nx, int Ny, const std::vector<short int>& image, const std::vector<Spherical> &sph, int counter){
heatmap_t* hm = heatmap_new(Nx, Ny); // auxiliar function
heatmap_add_weighted_point(hm, aprox_column, aprox_row, value);
}
heatmap.c
和heatmap.h
是从 https://github.com/lucasb-eyer/libheatmap 复制的
我的项目以Visual Studio Code
生成,但不使用QtCreator
我的CMakeLists.txt
:
cmake_minimum_required(VERSION 3.5)
project(trial LANGUAGES CXX)
set(ANDROID_NDK_ROOT "/Users/hectoresteban/Documents/C++/Qt/android-ndk-r21d")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# search for pkg-config
include (FindPkgConfig)
if (NOT PKG_CONFIG_FOUND)
message (FATAL_ERROR "pkg-config not found")
endif ()
find_package(Qt5 COMPONENTS Core LinguistTools REQUIRED)
set(TS_FILES trial_en_DE.ts)
add_executable(trial
main.cpp
${TS_FILES}
data.cpp
3rd_party/lodepng.cpp
3rd_party/heatmap.c
)
target_link_libraries(trial Qt5::Core)
更改
project(trial LANGUAGES CXX)
自
project(trial LANGUAGES C CXX)
或者根本不指定语言:
project(trial)
或者,您可以将其单独构建为库,然后将其链接到目标可执行文件:
add_library(heatmap
3rd_party/heatmap.h
3rd_party/heatmap.c
)
#...
target_link_libraries(trial Qt5::Core heatmap)
相关文章:
- 使用jsoncpp库时出现链接问题
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 如何将GTest与CMake一起使用?遵循谷歌指南时的链接问题
- 未解决的外部链接问题
- 'make check' GLIBC 运行时的链接问题
- 在树莓派上用libtorch构建程序时的链接问题
- 野牛弹性链接问题
- 与 AWS 开发工具包的链接问题
- Qt & Firebase C++ SDK 在 iOS 上的链接问题
- 链接问题 boost::p ython::numpy.
- 与 32 位共享对象的链接问题
- 在单元测试项目中包括 .c 文件,并从多个 cpp 文件访问它而不会出现链接问题
- 安卓链接问题
- LLVM 传递链接问题:未定义的符号
- Cmake Mac OSX库链接问题:在Linux上进行编译,但在Mac上进行了编译
- 用libclang解析源文件 - 链接问题包括文件
- C / C++链接问题与非常简单的设置
- Zbar 在 vs2015 链接问题
- Vulkan + GLFW + Cmake在Linux环境下的链接问题
- TFS构建由于链接问题而失败