I want to create dll file and link it. I refer this source : 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
I do some modify for create dll and link it :
1. (./src/calc/CMakeLists.txt)
cmake_minimum_required(VERSION 2.6)
project(calc)
add_library(calc calc.c)
after modify =>
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
after modify =>
#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 Cube(int x) { return x * x * x; }
int Square(int x) { return x * x; }
after modify =>
#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;
}
Do cmake :
cmake ../src -G "Visual Studio 15 2017"
MSBuild test_proj.sln
Go to executable file directory to execute:
/build/app/app.exe
Result is "cannot find calc.dll"
I copy it form dll builed directory. It execute normally.
I want to execute after build. Don't copy dll form dll directory to executable file directory. Does anybody can help me?