how to generate lib and include lib on windows?

Answered
  • I have already download https://github.com/jbeder/yaml-cpp, and built it with clion, so i got "libyaml-cpp.a" in my workpath "D:\github\yaml-cpp\cmake-build-debug".
  • Then I created new project(C++ Executable) , and modifed CMakeLists.text like this below:
cmake_minimum_required(VERSION 3.10)
project(testyaml)
link_directories(D:/github/yaml-cpp/cmake-build-debug)

include_directories(D:/github/yaml-cpp/include/yaml-cpp)

set(CMAKE_CXX_STANDARD 11)

add_executable(testyaml main.cpp)

#find_package (libyaml-cpp)

target_link_libraries(testyaml libyaml-cpp)

  • In my main.cpp, code like this:
#include <iostream>
#include <fstream>
#include <string>
#include "yaml.h"

int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
  • But when I build my project , Clion can't find yaml-cpp/parser.h. Is there something wrong with my CMakeList.txt?
"D:\Program Files\JetBrains\apps\CLion\ch-0\181.4668.70\bin\cmake\bin\cmake.exe" --build D:\github\testyaml\cmake-build-debug --target testyaml -- -j 2
Scanning dependencies of target testyaml
[ 50%] Building CXX object CMakeFiles/testyaml.dir/main.cpp.obj
In file included from D:\github\testyaml\main.cpp:4:0:
D:/github/yaml-cpp/include/yaml-cpp/yaml.h:10:29: fatal error: yaml-cpp/parser.h: No such file or directory
#include "yaml-cpp/parser.h"
 
0
4 comments

Hello!

  • Please change the line with include_directories in the following way:
include_directories(D:/github/yaml-cpp/include)
  • In your main.cpp do 
#include "yaml-cpp/yaml.h"
0
Avatar
Permanently deleted user

Thanks for replay!

I have done fellow your replay, but when i build my project , still get error:

"D:\Program Files\JetBrains\apps\CLion\ch-0\181.4668.70\bin\cmake\bin\cmake.exe" --build D:\github\testyaml\cmake-build-debug --target testyaml -- -j 2
Scanning dependencies of target testyaml
[ 50%] Building CXX object CMakeFiles/testyaml.dir/main.cpp.obj
[100%] Linking CXX executable testyaml.exe
D:/softwares/cloud/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llibyaml-cpp
collect2.exe: error: ld returned 1 exit status
CMakeFiles\testyaml.dir\build.make:96: recipe for target 'testyaml.exe' failed
mingw32-make.exe[3]: *** [testyaml.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/testyaml.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/testyaml.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/testyaml.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/testyaml.dir/rule] Error 2
Makefile:117: recipe for target 'testyaml' failed
mingw32-make.exe: *** [testyaml] Error 2
0

Please edit the line with target_link_libraries in the following way:

target_link_libraries(testyaml "D:/github/yaml-cpp/cmake-build-debug/libyaml-cpp.a")
0
Avatar
Permanently deleted user

It works!!!

Thanks very much, appreciate it!!

It troubled me few weeks!

0

Please sign in to leave a comment.