简体   繁体   English

如何修复cmake生成的Visual Studio项目中的包含错误

[英]How to fix include errors in resulting Visual Studio project from cmake

Please scroll to the bottom to list the updated short question 请滚动到底部以列出更新的简短问题

I am building PoDoFo . 我正在构建PoDoFo In the final step, I am using cmake to create the Visual Studio 2010 .sln file for PoDoFo. 在最后一步中,我将使用cmake为PoDoFo创建Visual Studio 2010 .sln文件。 However when I build this solution file, it can't find header files of dependent libraries. 但是,当我构建此解决方案文件时,它找不到依赖库的头文件。 For example, it doesn't find boost library header files. 例如,它没有找到boost库头文件。

c:\pdf\podofo-0.9.1\src\base\PdfDefines.h(66): fatal error C1083: Cannot open include file: 'boost/config.hpp': No such file or directory

If I disable boost, I get similar error for freetype library headers 如果禁用boost,我会在freetype库头文件中遇到类似错误

2>..\..\src\doc\PdfFontCache.cpp(55): fatal error C1083: Cannot open include file: 'ft2build.h': No such file or directory

Here is my build.cmd file 这是我的build.cmd文件

del cmakecache.txt

set BOOST_ROOT=C:\pdf\boost_1_51_0_code
set BOOST_INCLUDE_DIR=C:\pdf\boost\boost_1_51_0\staging\include
set BOOSTLIBDIR=C:\workspace\lib\boost\boost_1_51_0\staging\lib

set FT_INCLUDE=C:\PDF\freetype-2.4.0\include\freetype


set FTDIR=C:\PDF\freetype-2.4.0\objs\win32\vc2008
set JPEGDIR=C:\PDF\jpeg-8d\Release\lib
set TIFDIR=C:\PDF\tiff-4.0.3\lib
set ZLIBDIR=C:\pdf\zlib-1.2.8


set BUILD_FLAGS="/MT"

cmake  -G "Visual Studio 10" "C:\pdf\podofo-0.9.1" ^
    -DCMAKE_CXX_FLAGS_RELEASE:STRING=%BUILD_FLAGS%  ^
    -DFREETYPE_INCLUDE_DIR=%FT_INCLUDE% ^
    -DLIBJPEG_LIBRARY_RELEASE=jpeg ^
    -DCMAKE_INCLUDE_PATH="%INCLUDE%;%BOOST_INCLUDE_DIR%;%FT_INCLUDE%;%FT_INCLUDE%\freetype;%JPEGDIR%\jpeg;%TIFDIR%\tiff;%ZLIBDIR%\zlib" ^
    -DCMAKE_LIBRARY_PATH="%LIB%;%BOOSTLIBDIR%;%FTDIR%;%JPEGDIR%\lib;%TIFDIR%;%ZLIBDIR%\lib" ^
    -DPODOFO_BUILD_SHARED:BOOL=FALSE ^
    -DPODOFO_BUILD_STATIC:BOOL=TRUE ^
    -DWANT_BOOST:BOOL=0 ^
    -DLIBJPEG_LIBRARY_NAMES_RELEASE=jpeg ^
    -DFREETYPE_LIBRARY_NAMES_RELEASE=freetype240MT ^
    -DZLIB_LIBRARY_NAMES_RELEASE=zlibstat

I am new to CMake and I don't understand how the library dependencies carry through to the Visual Studio projects? 我是CMake的新手,我不了解库依赖关系如何传递到Visual Studio项目中? .

Here is the screen shot of the paths in resulting solution file. 这是生成的解决方案文件中路径的屏幕截图。 I can't understand how these paths carry through from the small script file? 我无法理解小脚本文件中这些路径的执行方式吗? They don't exactly correspond to DCMAKE_LIBRARY_PATH so where they come from? 它们与DCMAKE_LIBRARY_PATH并不完全对应,所以它们来自哪里?

Visual Studio项目中的项目路径-脚本文件的哪一部分来自?

How can I fix these include errors in the solution file? 如何解决解决方案文件中的这些包含错误? I tried adding these paths to Project Properites >> VC++ Directories >> 'Include Directories' but it still doesn't want to build. 我尝试将这些路径添加到Project Properites >> VC ++目录>>“包含目录”中,但是它仍然不想构建。 I am afraid even if I eliminate these include errors, I will get linker errors because the library paths are probably incorrect too. 即使消除了这些包含错误,我也担心会出现链接器错误,因为库路径也可能不正确。 How can I fix these error and get the project to build? 我该如何解决这些错误并建立项目? Thanks. 谢谢。

Updated question 更新的问题

I fixed the include error by changing the path to: 我通过将路径更改为来修复了包含错误:

FT_INCLUDE=C:\PDF\freetype-2.4.0\include\

Now as I expected, I get lots of linker errors. 现在,正如我所期望的,我收到许多链接器错误。 However I noticed that it did created PoDoFo.lib file so now I took the tast to use this in an example demo. 但是我注意到它确实创建了PoDoFo.lib文件,因此现在我尝试在示例演示中使用它。 I got that to compile as well successfully but I get the following linker errors: 我也可以成功编译,但是出现以下链接器错误:

1>podofo.lib(PdfFont.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
1>podofo.lib(PdfDifferenceEncoding.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
1>podofo.lib(PdfFontSimple.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
1>podofo.lib(PdfIdentityEncoding.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
1>podofo.lib(PdfFontTrueType.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
1>podofo.lib(PdfFontMetricsObject.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
1>podofo.lib(PdfEncodingObjectFactory.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4

I did made sure the the dependent libraries are added in project settings along with paths but why do I still get these errors? 我确实确保将依赖库与路径一起添加到项目设置中,但是为什么仍会出现这些错误?

Instead of using nmake directly, I'd recommend you use cmake-gui for building PoDoFo. 建议不要使用cmake-gui来构建PoDoFo,而不是直接使用nmake。 Don't write your own build.cmd as this doesn't work in most cases. 不要编写自己的build.cmd,因为在大多数情况下,这不起作用。 Note : The method described below uses your method, don't follow it. 注意:下述方法使用您的方法,请勿遵循。 Use cmake-gui (If you don't know how exactly cmake or nmake works). 使用cmake-gui(如果您不知道cmake或nmake的工作原理)。

Well I will recommend you go to this site and find the references: Building static podofo with MSVS 2012 Well I guess this should work for Visual Studio 2010. Remember : 好吧,我建议您访问此站点并找到参考资料: 使用MSVS 2012构建静态podofo我想这对于Visual Studio 2010应该适用。记住:

Building the prerequisite libraries - This site has also links about how to go on building these libraries. 构建必备库 -此站点还提供有关如何继续构建这些库的链接。 However, I assume you have already built them. 但是,我认为您已经构建了它们。 However I would recommend building them again according to this tutorial. 但是,我建议根据本教程再次构建它们。

Instructions : Do as he says. 说明 :按他说的做。 Don't miss any options regarding preprocessor definitions, runtime libraries and all the parameters same. 不要错过任何有关预处理器定义,运行时库和所有参数相同的选项。 If you miss anything or do something wrong that will force you to restart from where you started. 如果错过任何事情或做错了什么,将迫使您从开始的地方重新启动。

Errors : I myself experienced many errors while following the same procedure and this site provides no explanation. 错误 :按照相同的程序,我本人遇到许多错误,并且本网站未提供任何解释。 Common errors include: 常见错误包括:

Unresolved externals (either with msvcrt.lib or libcmt.lib). 无法解析的外部组件 (使用msvcrt.lib或libcmt.lib)。 In that case, just go to Linker>Input>Ignore specific libraries and name that library there to just ignore it. 在这种情况下,只需转到链接器>输入>忽略特定的库,然后在该库中命名该库即可将其忽略。 There will be random errors sometimes. 有时会出现随机错误。 I would suggest looking up Stack Overflow itself or MSDN or Google, because after starting off with >2500 errors I was finally able to build a static library. 我建议您查找Stack Overflow本身,MSDN或Google,因为从出现2500多个错误开始之后,我终于能够构建一个静态库。

Last Resort: If everything fails, just contact me (if you are still interested!). 不得已:如果一切失败,请与我联系(如果您仍然有兴趣!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM