【问题标题】:Reference static library project in Visual Studio在 Visual Studio 中引用静态库项目
【发布时间】:2015-09-24 09:07:57
【问题描述】:

TL;DR:如何使项目依赖于 Visual Studio 中的另一个静态库项目

我正在尝试制作一个使用此库的小型 C++ 项目:http://finitetransform.sourceforge.net/

该库包含两个项目。 NTTW 和 FRTW,其中 FRTW 取决于 NTTW。我的项目应该依赖于 FRTW。 NTTW 和 FRTW 以及相对较小且简单的库,没有任何外部依赖(除了 c 标准库)

现在我是 Visual Studio 中 C++ 开发的新手,但我一直在谷歌上搜索好几天,想知道如何设置它。

这就是我想要的: 我想要一个 Visual Studio 中的解决方案,我可以在其中构建 NTTW、FRTW 和我自己的 Playground 应用程序,我可以在其中使用库。我想从源代码构建这两个库,因为我可能想编辑它们。

这就是我所拥有的: 我已经在 Visual Studio 中创建了一个具有我想要的结构的解决方案。我已经创建了自己的项目(一个 c++ 控制台应用程序)和一个用于 NTTW 的项目和一个用于 FRTW 的项目 - 两者都创建了一个“静态库”。

由于库是用 C 语言编写的,因此我禁用了预编译头文件以便构建它们。 然后我将 NTTW 添加为 FRTW 的依赖项,并将 FRTW 添加为我的游乐场项目的依赖项。

什么有效:NTTW 构建得很好。但是,FRTW 没有,因为它无法链接到 NTTW。当我尝试构建它时,我收到这些错误,告诉我它无法从 NTTW 找到头文件

1>------ Build started: Project: FRTW, Configuration: Debug Win32 ------
1>  array_complex.c
1>  fourier.c
1>  ghosts.c
1>  mojette.c
1>  noise.c
1>  radon.c
1>  vector.c
1>u:\ct\newproject\fromsource\frtw\ghosts.c(26): fatal error C1083: Cannot open include file: 'nttw/image.h': No such file or directory
1>u:\ct\newproject\fromsource\frtw\radon.c(27): fatal error C1083: Cannot open include file: 'nttw/image.h': No such file or directory
1>u:\ct\newproject\fromsource\frtw\vector.h(29): fatal error C1083: Cannot open include file: 'nttw/array.h': No such file or directory (compiling source file vector.c)
1>u:\ct\newproject\fromsource\frtw\fourier.h(25): fatal error C1083: Cannot open include file: 'fftw3.h': No such file or directory (compiling source file fourier.c)
1>u:\ct\newproject\fromsource\frtw\array_complex.h(30): fatal error C1083: Cannot open include file: 'fftw3.h': No such file or directory (compiling source file array_complex.c)
1>u:\ct\newproject\fromsource\frtw\noise.h(45): fatal error C1083: Cannot open include file: 'nttw/global.h': No such file or directory (compiling source file noise.c)
1>u:\ct\newproject\fromsource\frtw\mojette.c(29): fatal error C1083: Cannot open include file: 'nttw/prime.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

我很不确定从这里该怎么做。任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: c++ c visual-studio-2013 msbuild static-libraries


    【解决方案1】:

    查看您的错误,我认为 FRTW 项目的调试配置设置需要更新 Additional Include Directories 设置以包含 nttw 目录的父目录。如果打开FRTW项目的属性页,可以在Configuration Properties -> C/C++ -> General下找到Additional Include Directories

    不要忘记 Debug 和 Release 有不同的设置,您可能会更改 Release 设置并在 Debug 下构建。

    您可能还需要更新 FRTW 项目以包含 NTTW 通过Configuration Properties -> Librarian -> General 生成的静态库文件,并将静态库将输出的目录添加到 @987654330 @ 和静态库的名称为Additional Dependencies。您可能需要执行与 Playground 应用项目类似的操作来导入 FRTW 可能生成的静态库。

    【讨论】:

    • 我目前正在测试您的建议,但我有一个愚蠢的问题。我注意到 FRTW(可能是因为我将它创建为静态库)没有“配置属性 - > 链接器”选项。我该怎么办?
    • 对不起,我已经更新了我的答案。您应该使用Librarian 而不是Linker,并且它应该包含相同的设置选项以允许您导入库。
    • 如果这解决了你的问题,你能接受答案吗?
    • 我正在更改 x64 的附加包含目录并在 x86 中运行,并且想知道为什么它不起作用。为所有平台添加额外的包含目录解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    相关资源
    最近更新 更多