It is my First time to use Boost lib, So of course I ran into problem:
First this is the CMAKELISTS.txt for my project:
===========================================
src/CMAKELISTS.txt:
===========================================
cmake_minimum_required(VERSION 3.15)
project(My_String)
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES MyString.cpp MyString.h main.cpp)
add_executable(My_String_src ${SOURCE_FILES})
===========================================
test/CMAKELISTS.txt:
===========================================
cmake_minimum_required(VERSION 3.15)
project(My_String)
set(CMAKE_CXX_STANDARD 17)
set(Boost_USE_STATIC_LIBS OFF)
set(SOURCE_FILES MyStringTest.cpp)
set(Boost_INCLUDE_DIR "C:\\Program Files\\Boost\\boost_1_71_0")
set(Boost_LIBRARIES "C:\\Program Files\\Boost\\boost_1_71_0")
find_package (Boost COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIR})
include_directories(../src)
add_executable (Boost_Tests_run ${SOURCE_FILES})
target_link_libraries (Boost_Tests_run ${Boost_LIBRARIES})
==============================================
top_level CMAKELISTS.txt for the whole project:
==============================================
cmake_minimum_required(VERSION 3.15)
project(My_String)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(src)
add_subdirectory(test)
Note: I have built the BOOST lib!enter code here
In MyStringTest.cpp I have:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE MyString_Test_Suite
#include <iostream>
#include "MyString.h"
#include "MyString.cpp"
#include <boost/test/unit_test.hpp>
The error that I get when I build the project:
[ 50%] Building CXX object test/CMakeFiles/Boost_Tests_run.dir/MyStringTest.cpp.obj
[100%] Linking CXX executable Boost_Tests_run.exe
C:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\ar.exe: unable to rename 'CMakeFiles\Boost_Tests_run.dir/objects.a'; reason: File exists
mingw32-make.exe[3]: *** [test\CMakeFiles\Boost_Tests_run.dir\build.make:86: test/Boost_Tests_run.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:141: test/CMakeFiles/Boost_Tests_run.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:148: test/CMakeFiles/Boost_Tests_run.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:130: Boost_Tests_run] Error 2
What is wrong with my configurations? And what do i need to do to fix it?