How to statically link to TBB?

后端 未结 7 2277
忘了有多久
忘了有多久 2020-12-05 19:00

How can I statically link the intel\'s TBB libraries to my application? I know all the caveats such as unfair load distribution of the scheduler, but I don\'t need the sched

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 19:07

    Just link the files, I just did it and works. Here's the SConscript file. There's two minor things, a symbol which has the same name in tbb and tbbmalloc which I had to prevent to be multiply defined, and I prevented the usage of ITT_NOTIFY since it creates another symbol with the same name in both libs.

    Import('g_CONFIGURATION')
    import os
    import SCutils
    import utils
    
    tbb_basedir = os.path.join(
        g_CONFIGURATION['basedir'],
        '3rd-party/tbb40_233oss/')
    
    #print 'TBB base:', tbb_basedir
    #print 'CWD: ', os.getcwd()
    
    ccflags = []
    cxxflags = [
        '-m64',
        '-march=native',
        '-I{0}'.format(tbb_basedir),
        '-I{0}'.format(os.path.join(tbb_basedir, 'src')),
        #'-I{0}'.format(os.path.join(tbb_basedir, 'src/tbb')),
        '-I{0}'.format(os.path.join(tbb_basedir, 'src/rml/include')),
        '-I{0}'.format(os.path.join(tbb_basedir, 'include')),
    ]
    cppdefines = [
    #    'DO_ITT_NOTIFY',
        'USE_PTHREAD',
        '__TBB_BUILD=1',
    ]
    linkflags = []
    
    if g_CONFIGURATION['build'] == 'debug':
        ccflags.extend([
            '-O0',
            '-g',
            '-ggdb2',
        ])
        cppdefines.extend([
            'TBB_USE_DEBUG',
        ])
    
    else:
        ccflags.extend([
            '-O2',
        ])
    
    
    tbbenv = Environment(
        platform = 'posix',
        CCFLAGS=ccflags,
        CXXFLAGS=cxxflags,
        CPPDEFINES=cppdefines,
        LINKFLAGS=linkflags
    )
    
    ############################################################################
    # Build verbosity
    if not SCutils.has_option('verbose'):
        SCutils.setup_quiet_build(tbbenv, True if SCutils.has_option('colorblind') else False)
    ############################################################################
    
    
    
    tbbmallocenv = tbbenv.Clone()
    
    tbbmallocenv.Append(CCFLAGS=[
        '-fno-rtti',
        '-fno-exceptions',
        '-fno-schedule-insns2',
    ])
    
    #tbbenv.Command('version_string.tmp', None, '')
    
    # Write version_string.tmp
    with open(os.path.join(os.getcwd(), 'version_string.tmp'), 'wb') as fd:
        (out, err, ret) = utils.xcall([
            '/bin/bash',
            os.path.join(g_CONFIGURATION['basedir'], '3rd-party/tbb40_233oss/build/version_info_linux.sh')
        ])
    
        if ret:
            raise SCons.Errors.StopError('version_info_linux.sh execution failed')
    
        fd.write(out);
        #print 'put version_string in', os.path.join(os.getcwd(), 'version_string.tmp')
        #print out
        fd.close()
    
    result = []
    
    def setup_tbb():
        print 'CWD: ', os.getcwd()
        tbb_sources = SCutils.find_files(os.path.join(tbb_basedir,'src/tbb'), r'^.*\.cpp$')
        tbb_sources.extend([
            'src/tbbmalloc/frontend.cpp',
            'src/tbbmalloc/backref.cpp',
            'src/tbbmalloc/tbbmalloc.cpp',
            'src/tbbmalloc/large_objects.cpp',
            'src/tbbmalloc/backend.cpp',
            'src/rml/client/rml_tbb.cpp',
        ])
    
    
        print tbb_sources
        result.append(tbbenv.StaticLibrary(target='libtbb', source=tbb_sources))
    
    
    setup_tbb()
    
    Return('result')
    

提交回复
热议问题