在linux中创建一个动态库,并使用Visual Studio linux Development链接到它
Create a dynamic library in linux and link to it using Visual Studio Linux Development
我需要使用Visual Studio linux Development Extension为linux创建动态库的帮助。我从来没有为linux开发过,但我做了研究,我被困住了。我不知道出了什么问题。
我正在使用这个扩展。https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/
这就是我所做的。首先,我在visual studio中创建了一个名为foo的空linux项目。我添加了一个名为foo.h和foo.cpp的类。
foo。
#ifndef foo_h__
#define foo_h__
extern void foo(void);
#endif
foo.cpp
#include <stdio.h>
void foo(void)
{
puts("Hello, I'm a shared library");
}
在配置属性中,我将配置类型从Application(.out)更改为Dynamic Library(.so)
C/c++ ->命令行->添加- fpic。
I saved and I build the project.
这是我的输出
1>------ Rebuild All started: Project: foo, Configuration: Debug x64 ------
1> Cleaning remote project directory
1> Validating architecture
1> Validating sources
1> Copying sources remotely
1> Starting remote build
1> Compiling sources:
1> foo.cpp
1>C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppBuild.targets(1190,5): warning MSB8012: TargetExt(.so.1.0) does not match the Linker's OutputFile property value (.0). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1>C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppBuild.targets(1191,5): warning MSB8012: TargetName(libfoo) does not match the Linker's OutputFile property value (libfoo.so.1). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1> Linking objects
1> foo.vcxproj -> C:UsersFantasy-DeskDesktoptestfoofoobinx64Debuglibfoo.so.1.0
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
之后,我创建了一个Linux控制台应用程序,它有一个main.cpp文件。
#include <stdio.h>
#include "../foo/foo.h"
int main(void)
{
puts("This is a shared library test...");
foo();
return 0;
}
在配置属性->链接器->输入->库依赖项中,我添加了"foo",在附加依赖项中,我添加了我的"libfoo.so.1.0"目录,在我的linux机器中是"projects/foo/bin/x64/Debug"
当我构建项目失败时,我得到这个输出
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug x64 ------
1> Validating architecture
1> Validating sources
1> Copying sources remotely
1> Starting remote build
1> Compiling sources:
1> main.cpp
1> Linking objects
1>/usr/bin/ld : error : File format not recognized
1>collect2 : error : ld returned 1 exit status
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
我想不明白,谷歌也帮不上忙。有人能告诉我什么是错的,为什么我不能编译和链接,并运行我的应用程序?
谢谢
在"Additional Dependencies"中,您需要指定实际的库文件名,而不是目录。
相关文章:
- 找不到Linux Visual Studio代码C++文件
- 在Visual Studio中将Windows解决方案移植到Linux
- 无法在clang Linux中分配非静态成员函数,但我可以在Visual Studio Windows中分配
- 从 Visual Studio 2017 指定 Linux 的外部库
- 无法将 Google Test NuGet 包添加到 Visual Studio Linux C++ 项目中
- 我可以在Windows(Visual C++)中读取bin文件,但不能在linux(GCC)上读取bin文件
- 如何在 Linux 中运行 Visual Studio 2015 托管 c++ 测试函数?
- 如何在Visual Studio c++ for Linux平台中编写GTK应用程序
- 如何在Visual Studio中添加Linux编译到Cmake Project
- 在 Linux 上从 Visual Studio Code 调试 Python C++ 扩展
- 在 Linux 上的 Visual Studio 中链接两个项目
- 将 PHP-CPP 库链接到 Visual Studio 2017 中的 Linux 项目
- Visual Studio 2017 Linux 远程构建 - 在每个构建中重新编译所有 cpp 文件
- Visual Studio 2017问题编译了C 代码,而该代码则在Linux中编译
- 正在从Visual Studio 2017创建Linux共享库
- 调试基于 Linux 的 C++ 代码 Visual Studio 代码时出现问题
- 如何在 Linux 上高效地编译 Visual Studio c++ 项目
- Visual Studio Linux跨平台的Cmake Generator
- Visual Studio 2017远程构建Linux具有Boost
- 使用 Visual Studio Code 在 Linux 中创建和编译"hello world"应用程序