gpt4 book ai didi

C++ 共享库到 main.cpp

转载 作者:行者123 更新时间:2023-11-30 03:15:28 25 4
gpt4 key购买 nike

<分区>

我正在尝试使用 CMake 在我的主程序中包含共享库。

我用了这个例子Trying to build shared library in CLion/CMakeC++ Link two Shared Library to main.cpp但它不工作。我得到了对所有函数调用的 undefined reference 。

我的目录树是这样的:

**folder**
| **project folder**
| |
| |_main.cpp
|_
| |_CMakeLists.txt
| |
| **lib**
|_**lib1**
|_CMakeLists.txt
|_liblib1.so
|_**src**
|_lib1.cpp
|_**include**
|_lib1.h

这是我的项目的CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(DAL_project)

set(CMAKE_CXX_STANDARD 17)
set(GCC_COVERAGE_COMPILE_FLAGS "-lpq")
set(GCC_COVERAGE_LINK_FLAGS "-lpq")

include_directories(/usr/include)
include_directories(-I/home/yaodav/Desktop/git_repo/lib/internal/conn2/include/)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
SET(SOURCE_FILES main.cpp SymbolInfo.cpp SymbolInfo.h SymbolDAL.cpp SymbolDAL.h AppSettingDAL.cpp AppSettingDAL.h AppSetting.cpp AppSetting.h)
add_executable(DAL_project ${SOURCE_FILES} )

我正在尝试将这些行添加到 CMakeLists.txt 但它不起作用:

target_link_libraries(DAL_project conlibcon.so)
add_library(libconnlib SHARED IMPORTED -L../lib/internal/conn1)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com