【发布时间】:2016-09-18 17:51:35
【问题描述】:
我需要有关使用 Visual Studio Linux 开发扩展为 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.h
#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”。
我保存并构建了项目。
这是我的输出
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)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.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)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.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:\Users\Fantasy-Desk\Desktop\test\foo\foo\bin\x64\Debug\libfoo.so.1.0
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
之后,我创建了一个包含 main.cpp 文件的 Linux 控制台应用程序。
#include <stdio.h>
#include "../foo/foo.h"
int main(void)
{
puts("This is a shared library test...");
foo();
return 0;
}
在配置属性 -> 链接器 -> 输入 -> 库依赖项中,我添加了“foo”,在附加依赖项中,我在我的 linux 机器中添加了“libfoo.so.1.0”目录,即“projects/foo/bin/ x64/调试”
当我构建项目时它失败了,我得到了这个输出
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 ==========
我无法弄清楚这一点,谷歌也无济于事。谁能告诉我哪里出了问题,为什么我不能编译、链接和运行我的应用程序?
谢谢
【问题讨论】:
标签: c++ c linux visual-studio-2015