Kan*_*nth 5 c++ ubuntu qt cmake conan
我是 StackOverflow、Conan 和 CMake 的新手。
我正在尝试使用 CMake 构建一个依赖于 Qt 的 hello world 程序。我已经从公共存储库cmake-hello-world克隆了它并成功编译了它。
现在,我正在尝试conanize这个项目,并且我已经安装了Qt/5.9@bincrafters/stable jfrog-bintray组件,该组件随时可用bintray并更改了 CMakelist.txt。
这是我的柯南简介:
cat ~/.conan/profiles/default
[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=5
compiler.libcxx=libstdc++
build_type=Release
[options]
[build_requires]
[env]
Run Code Online (Sandbox Code Playgroud)
CMakeList.txt:
cmake_minimum_required(VERSION 3.5)
project(helloworld)
# If conan is being used, configure CMake to use conan for dependencies.
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
# Find includes in the build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Turn on automatic invocation of the MOC, UIC & RCC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# There may be a way to tell up front if Qt5 is going to be found, but I haven't found
# a foolproof way to do it yet, so settle for the default error message for now.
#if(NOT CMAKE_PREFIX_PATH AND NOT Qt5Widgets_DIR)
# message(WARNING "CMAKE_PREFIX_PATH is not defined, so find_package may not work.
Set the CMAKE_PREFIX_PATH "
# "environment variable to the install prefix of Qt 5, either on the command line as "
# "-DCMAKE_PREFIX_PATH=\"path/to/Qt5/lib/cmake\" or with set(CMAKE_PREFIX_PATH path/to/Qt5/lib/cmake)")
#endif(NOT CMAKE_PREFIX_PATH AND NOT Qt5Widgets_DIR)
# Add a compiler flag
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Make this a GUI application on Windows
if(WIN32)
set(CMAKE_WIN32_EXECUTABLE ON)
endif()
# Find the QtWidgets library
find_package(Qt5 REQUIRED COMPONENTS Widgets)
# Tell CMake to create the helloworld executable
add_executable(helloworld main.cpp mainwindow.cpp mainwindow.ui resources.qrc)
# Add the Qt5 Widgets for linking
target_link_libraries(helloworld ${CONAN_LIBS})
Run Code Online (Sandbox Code Playgroud)
从目录的根目录,我运行以下命令:
mkdir build
cd build
conan install .. --build missing
cmake ..
make
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
cmake_minimum_required(VERSION 3.5)
project(helloworld)
# If conan is being used, configure CMake to use conan for dependencies.
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
# Find includes in the build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Turn on automatic invocation of the MOC, UIC & RCC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# There may be a way to tell up front if Qt5 is going to be found, but I haven't found
# a foolproof way to do it yet, so settle for the default error message for now.
#if(NOT CMAKE_PREFIX_PATH AND NOT Qt5Widgets_DIR)
# message(WARNING "CMAKE_PREFIX_PATH is not defined, so find_package may not work.
Set the CMAKE_PREFIX_PATH "
# "environment variable to the install prefix of Qt 5, either on the command line as "
# "-DCMAKE_PREFIX_PATH=\"path/to/Qt5/lib/cmake\" or with set(CMAKE_PREFIX_PATH path/to/Qt5/lib/cmake)")
#endif(NOT CMAKE_PREFIX_PATH AND NOT Qt5Widgets_DIR)
# Add a compiler flag
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Make this a GUI application on Windows
if(WIN32)
set(CMAKE_WIN32_EXECUTABLE ON)
endif()
# Find the QtWidgets library
find_package(Qt5 REQUIRED COMPONENTS Widgets)
# Tell CMake to create the helloworld executable
add_executable(helloworld main.cpp mainwindow.cpp mainwindow.ui resources.qrc)
# Add the Qt5 Widgets for linking
target_link_libraries(helloworld ${CONAN_LIBS})
Run Code Online (Sandbox Code Playgroud)
我在网上找不到太多帮助。请帮忙
感谢您的所有回答。下面的解决方案对我有用,这就是我的 CMakeList 文件的样子。我发帖是因为以下信息可能对其他人有帮助。
cmake_minimum_required(VERSION 3.5)
project(helloworld)
# Find includes in the build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
# Turn on automatic invocation of the MOC, UIC & RCC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
include_directories(${CONAN_INCLUDE_DIRS})
# There may be a way to tell up front if Qt5 is going to be found, but I haven't found
# a foolproof way to do it yet, so settle for the default error message for now.
#if(NOT CMAKE_PREFIX_PATH AND NOT Qt5Widgets_DIR)
# message(WARNING "CMAKE_PREFIX_PATH is not defined, so find_package may not work. Set the CMAKE_PREFIX_PATH "
# "environment variable to the install prefix of Qt 5, either on the command line as "
# "-DCMAKE_PREFIX_PATH=\"path/to/Qt5/lib/cmake\" or with set(CMAKE_PREFIX_PATH path/to/Qt5/lib/cmake)")
#endif(NOT CMAKE_PREFIX_PATH AND NOT Qt5Widgets_DIR)
# Add a compiler flag
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Make this a GUI application on Windows
if(WIN32)
set(CMAKE_WIN32_EXECUTABLE ON)
endif()
# Find the QtWidgets library
find_package(Qt5 REQUIRED COMPONENTS Widgets)
# Tell CMake to create the helloworld executable
add_executable(helloworld main.cpp mainwindow.cpp mainwindow.ui resources.qrc)
# Add the Qt5 Widgets for linking
target_link_libraries(helloworld Qt5::Widgets)
# target_link_libraries(helloworld ${CONAN_LIBS})
Run Code Online (Sandbox Code Playgroud)
这是我的 conanfile.py
from conan_base import <your import module here>
class HelloWorld(your import module here):
name = "HelloWorld"
license = "BSD"
author = "your name"
url = "git@gitlab.com:<url/project>"
description = "Base Library A of the example project."
topics = ("<Put some tag here>", "<here>", "<and here>")
def build_requirements(self):
self.build_requires("gtest/1.8.1@bincrafters/stable")
def requirements(self):
self.requires("Qt/5.11.2@bincrafters/stable")
# def package_info(self):
# self.cpp_info.libs = ["BaseLibBLibrary"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5732 次 |
| 最近记录: |