2013-02-28 7 views
5

मैं स्कैन के साथ समान स्रोतों का उपयोग करके एक स्थिर और साझा लाइब्रेरी बनाने की कोशिश कर रहा हूं।स्कैन स्थिर और साझा लाइब्रेरी दोनों निर्मित करते हैं

सब कुछ ठीक काम करता है अगर मैं सिर्फ एक या अन्य निर्माण, लेकिन जैसे ही मैं दोनों का निर्माण करने की कोशिश करते हैं, केवल स्थिर पुस्तकालय बनाया गया है।

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) 

मैं भी SharedObject (स्रोत) SharedLibrary से पहले (SharedObject से बदले में गुजर, बल्कि स्रोतों की तुलना में) की कोशिश की है, लेकिन यह अलग नहीं है:

मेरे SConscript तरह दिखता है। वैसे ही अगर मैं .so से पहले .a बना देता हूं।

मैं इस के आसपास कैसे काम करते हैं?

उत्तर

6

जब स्थापना निर्देशिका में या वर्तमान निर्देशिका नीचे नहीं है, SCons के रूप में SCons Install method docs:

नोट टिप्पणी की अपेक्षा के अनुरूप व्यवहार नहीं करता है, यह है कि एक फ़ाइल को स्थापित करने से अभी भी एक प्रकार माना जाता है फ़ाइल "बिल्ड"। यह महत्वपूर्ण है जब आपको याद रखें कि डिफ़ॉल्ट स्कैन का व्यवहार वर्तमान निर्देशिका में या नीचे फ़ाइलों को बनाना है। यदि उपर्युक्त उदाहरण में, आप निर्देशिका में फ़ाइलों को शीर्ष-स्तरीय स्कैनस्ट्रक्चर फ़ाइल के निर्देशिका पेड़ के बाहर स्थापित कर रहे हैं, तो आपको उस निर्देशिका को निर्दिष्ट करना होगा (या उच्च निर्देशिका, जैसे कि /) इसके लिए कुछ भी इंस्टॉल करें वहाँ:

है यही कारण है कि, आप के लिए एक लक्ष्य के रूप में स्थापित करने के लिए निर्देशिका (आपके मामले में SP3_env['SP3_lib_dir']) के साथ SCons आह्वान करना चाहिए के लिए स्थापना निष्पादित किया जाना है। इसे सरल बनाने के लिए, नीचे दिए गए अनुसार env.Alias() का उपयोग करें।

जब आप SCons आह्वान, आप कम से कम यह देखना चाहिए कि दोनों स्थिर और साझा पुस्तकालयों स्थानीय परियोजना dir में बनाया जाता है। हालांकि, मैं कल्पना करता हूं कि स्कॉन्स उन्हें स्थापित नहीं करता है।

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 निष्पादित, मैं निम्नलिखित: यहाँ एक उदाहरण है कि काम करता है मैं Ubuntu पर बनाई गई है

# 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. 

या, आप यह सब सिर्फ कर सकता है एक आदेश, पहले साफ सब कुछ के साथ

# scons -c install 

फिर, यह सब सिर्फ एक आदेश के साथ कार्य करें:

# 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. 
संबंधित मुद्दे