CLion 内置的库无法动态连接到另一个项目

问题描述

我在 CLion IDE 中工作。我需要获取共享库 (.dll)。为此,我在文件 .cpp 中编写了一些代码。 h,和 CMakeLists.txt。项目构建成功 - 我得到了我的库中带有 .dll 扩展名的珍贵文件

接下来,我有一个可以动态加载库的程序。因此,例如,我可以加载我计算机中的任何一个 .the dll 库。所以我可以自信地说这个程序运行正常。但是,我无法加载自己的 CLion 内置库:出现错误

请告诉我,可能是什么问题?

1.图书馆.h

#pragma once

#define MY_LIB extern "C" __declspec(dllexport)

MY_LIB void testa(int a);
MY_LIB bool testb();

2. library.cpp

#include "library.hpp"
#include <iostream>

void testa(int a) {
    std::cout << "The function A called" << std::endl;
}

bool testb() {
    std::cout << "The function B called" << std::endl;
    return true;
}

3. CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project (cmake_example_4_shared)

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall")


#-------------------- Create a library -----------------------------------------
#Generate the shared library from the library sources
#-------------------------------------------------------------------------------

include_directories("${PROJECT_SOURCE_DIR}/include")

add_library(${PROJECT_NAME}_lib
        SHARED
        src/library.cpp
        )

4.我的构建成功的证明

Scanning dependencies of target cmake_example_4_shared_lib
[ 50%] Building CXX object CMakeFiles/cmake_example_4_shared_lib.dir/src/library.cpp.obj
[100%] Linking CXX shared library libcmake_example_4_shared_lib.dll
[100%] Built target cmake_example_4_shared_lib

非常感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)