我想创建dll文件并将其链接。 我参考这个来源: https://zh.wikibooks.org/wiki/CMake_%E5%85%A5%E9%96%80/%E5%BB%BA%E7%BD%AE%E8%88%87%E9%80%A3%E7%B5%90%E7%A8%8B%E5%BC%8F%E5%BA%AB
我对创建dll进行了一些修改并将其链接:
1。 (./src/calc/CMakeLists.txt)
cmake_minimum_required(VERSION 2.6)
project(calc)
add_library(calc calc.c)
修改后=>
cmake_minimum_required(VERSION 2.6)
project(calc)
add_library(calc SHARED calc.c)
2。 (./src/calc/calc.h)
#ifndef CALC_H_
#define CALC_H_
int Cube(int x);
int Square(int x);
#endif
修改后=>
#ifndef CALC_H_
#define CALC_H_ ()
#if defined(_WIN64) && defined(calc_EXPORTS)
# if defined(LIBCALC_INTERNAL)
# define LIBCALC_API __declspec (dllexport)
# else
# define LIBCALC_API __declspec (dllimport)
# endif
#endif
#if !defined(LIBCALC_API)
# define LIBCALC_API
#endif
LIBCALC_API int Cube(int x);
LIBCALC_API int Square(int x);
#endif
(./ src / calc / calc.c)
int多维数据集(int x) { 返回x * x * x; }
int Square(int x) { 返回x * x; }
修改后=>
#define LIBCALC_INTERNAL
#include "calc.h"
LIBCALC_API int Cube(int x)
{
return x * x * x;
}
LIBCALC_API int Square(int x)
{
return x * x;
}
做cmake:
cmake ../src -G "Visual Studio 15 2017"
MSBuild test_proj.sln
转到可执行文件目录以执行:
/build/app/app.exe
结果是“找不到calc.dll”
我将其复制到dll内置目录中。 它正常执行。
我想在构建后执行。 不要将dll形式的dll目录复制到可执行文件目录。 有人可以帮助我吗?