2016-09-18 11 views
0

Visual Studio Linux Development Extensionを使用してLinux用の動的ライブラリを作成する際に助けが必要です。私はLinux用に開発したことはありませんが、私は研究をしました。何が間違っているのか分かりません。linuxで動的ライブラリを作成し、Visual Studio Linux Developmentを使用してそのライブラリにリンクします。

この拡張機能を使用しています。 https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

ここには私がしたことがあります。最初に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"); 
} 

は、私は動的ライブラリ(.soという)

へのアプリケーション(の.out)から構成タイプを変更しましたC/C++ - >コマンドライン - > "-fpic"を追加しました。

保存してプロジェクトを作成しました。私はmain.cppにファイルを持っているLinuxのコンソールアプリケーションを作成した後

これは私の出力

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 ========== 

です。 >リンカ - - >入力 - 私は「foo」を追加し、追加の依存で、私は「プロジェクト/である私のLinuxマシンで私の「libfoo.so.1.0」ディレクトリを追加]> [ライブラリの依存関係設定のプロパティで

#include <stdio.h> 
#include "../foo/foo.h" 

int main(void) 
{ 
    puts("This is a shared library test..."); 
    foo(); 
    return 0; 
} 

私はそれが失敗したプロジェクトをビルドし、私は、この出力

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 ========== 

を取得した場合のfoo/binに/ x64の/デバッグ」

私はこれを把握することはできませんし、Googleは何の助けではありません。誰かが間違っていることを教えてもらえますか、なぜアプリケーションをコンパイルしてリンクして実行できないのですか? 「追加の依存」で

答えて

0

おかげで、あなたは実際のライブラリファイル名ではなくディレクトリを指定する必要があります。

+0

追加の依存関係にlibfoo.so.1.0を追加する場合「projects/foo/bin/x64/lib」を追加すると「1> g ++:error:No such file or directory」という出力ファイルにエラーが発生します。 Debug/libfoo.so.1.0 "" collect2:エラー:ldが1つの終了ステータスを返しました "というエラーが表示される – user2204292

+0

これを追加の依存関係に追加した後で、" projects/foo/bin/x64/Debug/libfoo.so .1.0 "ライブラリの依存関係から" foo "を削除すると、アプリケーションがコンパイルされ、.outファイルが取得されます。しかし、私はそれを実行すると、 "共有ライブラリをロード中にエラー:projects/foo/bin/x64/Debug/libfoo.so.1.0。"というエラーが表示される共有オブジェクトファイル名を開くことができません:そのようなファイルやディレクトリ " – user2204292

関連する問題