5

SCons と同じソースを使用して、静的ライブラリと共有ライブラリの両方を構築しようとしています。

どちらか一方だけをビルドするとすべて正常に動作しますが、両方をビルドしようとするとすぐに静的ライブラリのみがビルドされます。

私の SConscript は次のようになります。

cppflags = SP3_env['CPPFLAGS']
cppflags += ' -fPIC '
SP3_env['CPPFLAGS'] = cppflags

soLibFile = SP3_env.SharedLibrary(
   target = "sp3",
   source = sources)
installedSoFile = SP3_env.Install(SP3_env['SP3_lib_dir'], soLibFile)

libFile = SP3_env.Library(
    target = "sp3",
    source = sources)
installedLibFile = SP3_env.Install(SP3_env['SP3_lib_dir'], libFile)

また、SharedLibrary の前に SharedObject(sources) を試しました (ソースではなく、SharedObject からの戻り値を渡します) が、違いはありません。.so の前に .a をビルドしても同じです。

これを回避するにはどうすればよいですか?

4

1 に答える 1

6

インストールディレクトリが現在のディレクトリ内またはその下にない場合、 SConsインストールメソッドのドキュメントでコメントされているように、SConsは期待どおりに動作しません。

ただし、ファイルのインストールは、ファイルの「ビルド」の一種と見なされることに注意してください。これは、SConsのデフォルトの動作が、現在のディレクトリ内またはその下にファイルをビルドすることであることを覚えている場合に重要です。上記の例のように、最上位のSConstructファイルのディレクトリツリーの外部のディレクトリにファイルをインストールする場合、そこに何かをインストールするには、そのディレクトリ(または/などの上位ディレクトリ)を指定する必要があります。

つまり、SP3_env['SP3_lib_dir']インストールを実行するには、(この場合は)インストールディレクトリをターゲットとしてSConsを呼び出す必要があります。これを単純化するために、以下のように使用env.Alias()します。

SConsを呼び出すときは、少なくとも静的ライブラリと共有ライブラリの両方がローカルプロジェクトディレクトリに構築されていることを確認する必要があります。ただし、SConsはそれらをインストールしないと思います。これが私がUbuntuで作った例です。

env = Environment()

sourceFiles = 'ExampleClass.cc'

sharedLib = env.SharedLibrary(target='example', source=sourceFiles)
staticLib = env.StaticLibrary(target='example', source=sourceFiles)

# Notice that installDir is outside of the local project dir
installDir = '/home/notroot/projects/sandbox'

sharedInstall = env.Install(installDir, sharedLib)
staticInstall = env.Install(installDir, staticLib)

env.Alias('install', installDir)

ターゲットなしでsconsを実行すると、次のようになります。

# scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o ExampleClass.o -c ExampleClass.cc
g++ -o ExampleClass.os -c -fPIC ExampleClass.cc
ar rc libexample.a ExampleClass.o
ranlib libexample.a
g++ -o libexample.so -shared ExampleClass.os
scons: done building targets.

次に、次のように、インストールターゲットでsconsを実行してインストールできます。

# scons install
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
Install file: "libexample.a" as "/home/notroot/projects/sandbox/libexample.a"
Install file: "libexample.so" as "/home/notroot/projects/sandbox/libexample.so"
scons: done building targets.

または、1つのコマンドですべてを実行し、最初にすべてをクリーンアップすることもできます

# scons -c install

次に、1つのコマンドですべてを実行します。

# scons install
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o ExampleClass.o -c ExampleClass.cc
g++ -o ExampleClass.os -c -fPIC ExampleClass.cc
ar rc libexample.a ExampleClass.o
ranlib libexample.a
g++ -o libexample.so -shared ExampleClass.os
Install file: "libexample.a" as "/home/notroot/projects/sandbox/libexample.a"
Install file: "libexample.so" as "/home/notroot/projects/sandbox/libexample.so"
scons: done building targets.
于 2013-03-03T11:21:58.153 に答える