2013-02-10 67 views
5

पथ शामिल करना शामिल है मैं wscript में पथ शामिल कैसे जोड़ सकता हूं?वाफ कॉन्फ़िगरेशन (सी ++)

मैं जानता हूँ कि मैं घोषणा कर सकते हैं जो फ़ाइलों जहाँ से फ़ोल्डरों मैं किसी भी cpp फ़ाइल प्रति शामिल करना चाहते हैं, जैसे:

def build(bld): 
    bld(features='c cxx cxxprogram', 
     includes='include', 
     source='main.cpp', 
     target='app', 
     use=['M','mylib'], 
     lib=['dl']) 

लेकिन मैं हर फ़ाइल प्रति यह स्थापित करने के लिए नहीं करना चाहती। मैं "वैश्विक शामिल" के लिए एक पथ जोड़ना चाहता हूं, इसलिए प्रत्येक बार किसी भी फाइल को संकलित किया जाएगा।

उत्तर

8

मुझे एक उत्तर मिला है। आपको बस अपनी इच्छित पथों की सूची में 'INCLUDES' का मान सेट करना होगा। waf configure फिर से चलाने के लिए मत भूलना :)

def configure(cfg): 
    cfg.env.append_value('INCLUDES', ['include']) 
+0

मैंने स्वतंत्र रूप से इस उत्तर पर अभिसरण किया, लेकिन मैं यह उम्मीद कर रहा था कि ऐसा करने के लिए एक और ओएस स्वतंत्र तरीका था। – meawoppl

2

मैं एक अच्छा तरीका है बाहर काम कर रहे इस bld.program में विकल्प "का उपयोग" का उपयोग() पद्धतियों करने के लिए कुछ समय बिताया। एक उदाहरण के रूप में बढ़ावा पुस्तकालयों के साथ काम करना, मैं निम्नलिखित के साथ आया था। मुझे उम्मीद है यह मदद करेगा!

''' 
run waf with -v option and look at the command line arguments given 
to the compiler for the three cases. 

you may need to include the boost tool into waf to test this script. 
''' 
def options(opt): 
    opt.load('compiler_cxx boost') 

def configure(cfg): 
    cfg.load('compiler_cxx boost') 
    cfg.check_boost() 

    cfg.env.DEFINES_BOOST = ['NDEBUG'] 

    ### the following line would be very convenient 
    ###  cfg.env.USE_MYCONFIG = ['BOOST'] 
    ### but this works too: 
    def copy_config(cfg, name, new_name): 
     i = '_'+name 
     o = '_'+new_name 
     l = len(i) 
     d = {} 
     for key in cfg.env.keys(): 
      if key[-l:] == i: 
       d[key.replace(i,o)] = cfg.env[key] 
     cfg.env.update(d) 

    copy_config(cfg, 'BOOST', 'MYCONFIG') 

    # now modify the new env/configuration 
    # this adds the appropriate "boost_" to the beginning 
    # of the library and the "-mt" to the end if needed 
    cfg.env.LIB_MYCONFIG = cfg.boost_get_libs('filesystem system')[-1] 

def build(bld): 

    # basic boost (no libraries) 
    bld.program(target='test-boost2', source='test-boost.cpp', 
       use='BOOST') 

    # myconfig: boost with two libraries 
    bld.program(target='test-boost', source='test-boost.cpp', 
       use='MYCONFIG') 

    # warning: 
    # notice the NDEBUG shows up twice in the compilation 
    # because MYCONFIG already includes everything in BOOST 
    bld.program(target='test-boost3', source='test-boost.cpp', 
       use='BOOST MYCONFIG') 
0

मैं इस पता लगा और कदम इस प्रकार हैं: WScript फ़ाइल में कॉन्फ़िगर समारोह में

जोड़ा निम्नलिखित की जांच। यह स्क्रिप्ट को दिए गए लाइब्रेरी फ़ाइल (इस मामले में libmongoclient) की जांच करने के लिए कहता है, और हम इस चेक के परिणामों को Mongongient में संग्रहीत करते हैं।

conf.check_cfg(package='libmongoclient', args=['--cflags', '--libs'], uselib_store='MONGOCLIENT', mandatory=True) 

इस कदम के बाद, हम/usr/स्थानीय/lib/pkgconfig मार्ग में एक पैकेज विन्यास फाइल (.pc) जोड़ने की जरूरत है। यह वह फ़ाइल है जहां हम lib और हेडर के पथ निर्दिष्ट करते हैं। नीचे इस फ़ाइल की सामग्री चिपका रहा है।

prefix=/usr/local 
libdir=/usr/local/lib 
includedir=/usr/local/include/mongo 

Name: libmongoclient 
Description: Mongodb C++ driver 
Version: 0.2 
Libs: -L${libdir} -lmongoclient 
Cflags: -I${includedir} 

जोड़ा गया sepcific प्रोग्राम है जो ऊपर पुस्तकालय (अर्थात MongoClient) पर निर्भर करता है के निर्माण कार्य में मिली निर्भरता। नीचे एक उदाहरण है।

mobility = bld(target='bin/mobility', features='cxx cxxprogram', source='src/main.cpp', use='mob-objects MONGOCLIENT',) 

इसके बाद, कॉन्फ़िगर को फिर से चलाएं, और अपना कोड बनाएं।

+1

भविष्य में, कृपया प्रश्न के अपने उत्तर तैयार करें, न केवल उत्तर को डुप्लिकेट करें। यहां, उत्तर दोनों प्रश्नों पर लागू होने के लिए * होता है *, और प्रश्न अलग-अलग हैं कि आप उन्हें डुप्लिकेट नहीं कर सकते हैं (एक जोड़ने के लिए पूछता है, दूसरा लाइब्रेरी जोड़ता है)। कम से कम प्रत्येक में यह बताएं कि यह प्रश्न में * विशिष्ट स्थिति * पर कैसे लागू होता है। –