2014-11-23 48 views
0

我试图构建和链接CLAM project的例子。我链接并得到以下错误。我不知道什么是错的。错误链接器C + +的Linux Scons:CLAM项目

>== Linking UserTutorial1 
>/usr/local/lib/libclam_core.so: undefined reference to `dlclose' 
>/usr/local/lib/libclam_core.so: undefined reference to `dlsym' 
>/usr/local/lib/libclam_core.so: undefined reference to `dlopen' 
>/usr/local/lib/libclam_core.so: undefined reference to `dlerror' 
>/usr/local/lib/libclam_core.so: undefined reference to `dladdr' 
>collect2: error: ld returned 1 exit status 
>scons: *** [UserTutorial1] Error 1 
>scons: building terminated because of errors. 

有没有人可以帮我解决这个问题。我应当怎样更改下面SConstruct所示:

>## #!/usr/bin/python 
>import os 
>import glob 
>import sys 
>options = Variables('options.cache', ARGUMENTS) 
>options.Add(PathVariable('clam_prefix', 'The prefix where CLAM was installed', '')) 
>options.Add(BoolVariable('verbose', 'Display the full command line instead a short command >description', 'no')) 
>options.Add(BoolVariable('crossmingw', 'Enables MinGW crosscompilation from linux', 'no')) 
>def scanFiles(pattern, paths) : 
> files = [] 
> for path in paths : 
>  files+=glob.glob(path+"/"+pattern) 
> return files 
>def recursiveDirs(root) : 
> return filter((lambda a : a.rfind(".svn")==-1), [ a[0] for a in os.walk(root)] ) 
>def unique(list) : 
> return dict.fromkeys(list).keys() 
>toolchain = 'default' 
>if sys.platform == "win32" : toolchain = 'mingw' 
>env = Environment(tools=[toolchain], options=options) 
>options.Save('options.cache', env) 
>#TODO: This didn't work for dynamic linking 
>def renameEmbededFileSymbols(source, target, env) : 
> """ Remove the path part of the symbol name for the embeded file""" 
> objdumpOutput=os.popen("objdump -x %s | grep _binary'.*'start"%target[0] , "r").read() 
> startSymbol=objdumpOutput.split()[-1] 
> infix = startSymbol[len('_binary_'):-len("_start")] 
> baseName = os.path.split(str(source[0]))[-1] 
> newInfix = infix[-len(baseName):] 
> return Execute("objcopy %(target)s " 
>  "--redefine-sym _binary_%(infix)s_start=_binary_%(newInfix)s_start " 
>  "--redefine-sym _binary_%(infix)s_end=_binary_%(newInfix)s_end " 
>  "--redefine-sym _binary_%(infix)s_size=_binary_%(newInfix)s_size " % { 
>   "infix": infix, 
>   "newInfix": newInfix, 
>   "target": target[0], 
>  } 
> ) 
>""" 
>embededFileBuilder = Builder(
> action=Action([ 
>  ["ld", "-fPIC", "--shared", "-b", "binary", "-o", "$TARGET", "$SOURCE"], 
>  renameEmbededFileSymbols, 
>  ], 
>  ), 
> suffix='.os', 
> ) 
>env['BUILDERS']['EmbededFile']=embededFileBuilder 
>""" 
>env.SConsignFile() # Single signature file 
>crosscompiling=env['crossmingw'] 
>CLAMInstallDir = env['clam_prefix'] 
>clam_sconstoolspath = os.path.join(CLAMInstallDir,'share','clam','sconstools') 
>env.Tool('clam', toolpath=[clam_sconstoolspath]) 
>env.Tool('qt4', toolpath=[clam_sconstoolspath]) 
>if crosscompiling : 
> env.Tool('crossmingw', toolpath=[clam_sconstoolspath]) 
>env.AppendUnique(ASFLAGS='-I. ') 
>env['CXXFILESUFFIX'] = '.cxx' 
>env['QT4_UICDECLSUFFIX'] = '.hxx' 
>env.moveIntermediateInto('generated') 
>env.activateColorCommandLine() 
>if not env['verbose']: env.ClamQuietCompilation() 
>env.EnableClamModules(libs=[ 
> 'clam_core', 
> 'clam_audioio', 
> 'clam_processing', 
> ], path=CLAMInstallDir) 
>env.EnableQt4Modules([ 
> 'QtCore', 
> 'QtGui', 
> 'QtOpenGL', 
># 'QtSql', 
># 'QtNetwork', 
># 'QtTest', 
># 'QtXml', 
># 'QtSvg', 
># 'QtUiTools', 
># 'QtDesigner', 
># 'Qt3Support', 
> ], debug=False, 
> crosscompiling=crosscompiling, 
> ) 
>sourcePaths = [] 
>extraPaths = [ 
> CLAMInstallDir+'/include', 
> CLAMInstallDir+'/include/CLAM', # KLUDGE to keep old style includes 
>] 
>includePaths = sourcePaths + extraPaths 
>sources = scanFiles('*.cxx', sourcePaths) 
>sources = unique(sources) 
>singleSourceExamples = [ 
> "WritingProcessings.cxx", 
> "NetworkPersistence_example.cxx", 
> "NetworkUsage_example.cxx", 
> "AudioFileReading_example.cxx", 
> "AudioFileWriting_example.cxx", 
> "AudioIOExample.cxx", 
># "Configurators_example.cxx", # QT4Port 
> "DescriptorComputation_example.cxx", 
> "FDFilterExample.cxx", 
> "FFT_example.cxx", 
> "FileInfo_example.cxx", 
> "FilePlayback_example.cxx", 
> "FundamentalDetect.cxx", 
> "LPCAnalysis_example.cxx", # TODO FLTK Dependencies -> Qt4 
> "Midi2XmlExample.cxx", 
> "MIDIFileReadWriteExample.cxx", 
> "MIDIIOExample.cxx", 
> "MIDIOut_example.cxx", 
> "MIDI_Synthesizer_example.cxx", 
> "NetworkPersistence_example.cxx", 
> "NetworkUsage_example.cxx", 
> "OfflineAudioConvolution.cxx", 
> "PersistenceThroughDTs_example.cxx", 
> "POCompositeExample.cxx", 
> "SimplePortsUsage_example.cxx", 
> "ProcessingLifeCycle_example.cxx", 
> "ProcessingObject_controls_example.cxx", 
> "SDIF_And_Segment_example.cxx", # TODO: FLTK Dependencies 
> "Spectrum_example.cxx", 
> "StereoToMonoFile.cxx", 
># "ThreadedProcessing_example.cxx", # TODO: Depends on Resample and FLTK 
> "Tutorial/UserTutorial1.cxx", 
> "Tutorial/UserTutorial2.cxx", 
> "Tutorial/UserTutorial3.cxx", 
> "Tutorial/UserTutorial4.cxx", 
> "Tutorial/UserTutorial5.cxx", 
> "Tutorial/UserTutorial6.cxx", 
>] 
>directoryBasedExamples = [ 
> "PortsAndControlsUsageExample", 
> "ControlArrayExamples", 
> "Wav2SDIF", 
> "SDIF2Wav", 
> "SDIF2WavStreaming", 
>] 
>directoryBasedLibraries = [ 
># "PluginExamples/ClamLadspaPluginExample", 
> "PluginExamples/ClamNativePluginExample", 
>] 
>singleSourceLibraries = [ 
>] 
>env.Append(CPPPATH=includePaths) 
>env.AppendUnique(CPPFLAGS=["-g", "-Wall"]) 
>#env.AppendUnique(DEFINES=["_DEBUG"]) 
>examples = [] 
>for libsource in singleSourceLibraries : 
> library = os.path.basename(libsource) 
> examples += [ env.SharedLibrary(source = libsource) ] 
>for folder in directoryBasedLibraries : 
> librarySources = glob.glob(folder+"/*.cxx") 
># librarySources += [env.EmbededFile(file) for file in glob.glob(folder+"/*.clamnetwork")] 
> library = os.path.basename(folder) 
> examples += [ env.SharedLibrary(target=library, source = librarySources) ] 
>for main in singleSourceExamples : 
> executable = os.path.splitext(os.path.basename(main))[0] 
> examples += [ env.Program(target=executable, source = sources + [main]) ] 
>for folder in directoryBasedExamples : 
> exampleSources = glob.glob(folder+"/*.cxx") 
> executable = os.path.basename(folder)+"Exe" 
> examples += [ env.Program(target=executable, source = sources + exampleSources) ] 
>if not crosscompiling : 
> # Still having problems crosscompiling aubio 
> tickEnv = env.Clone() 
> tickEnv.ParseConfig('pkg-config aubio --cflags --libs') 
> tickEnv.ParseConfig('pkg-config samplerate --cflags --libs') 
> tickSrc = glob.glob("TickExtractor/*cxx") 
> examples += [ tickEnv.Program(target="TickExtractorExe", source = tickSrc) ] 
>env.Alias('examples',examples) 
>env.Default(examples) 
+0

看起来你缺少libdl。不知道你在哪里添加它。 – cup 2014-11-23 07:19:21

+0

谢谢;我想是的,但在哪里,我也想知道... – telcom 2014-11-23 07:44:54

+0

设置CPPPATH – cup 2014-11-23 08:06:36

回答

2

我不认为你必须改变在SConstruct什么,似乎这个错误并没有从我的角度看,在所有涉及到SCons的。该错误消息显示您安装的/usr/local/lib/libclam_core.so取决于未解析的符号。这会给你带来麻烦,即使试图在命令行中将“clam_core”与简单的C++主程序链接起来。

尝试使用“ldd”检查“clam_core”库的动态依赖关系。可以在标准shell中解析dlopen调用吗?如果这可以在命令行运行,但不在SCons中运行,那么您可能在shell环境中设置了LD_LIBRARY_PATH以使其工作。然后,您必须将此路径传播到SCons,或者,甚至更好地正确安装所需的CLAM库,以便无需LD_LIBRARY_PATH即可解析其依赖关系。

检查您的CLAM库的安装。你是从源代码编译它们还是使用二进制包?在后一种情况下,您是否为您的机器/架构选择了合适的?

+0

感谢您的答案。其实我已经从源代码编译,所以之后得到了二进制文件没有任何错误。 关于路径,我已经检查过,似乎我有“ldd”的问题,设置路径并没有帮助我到目前为止... – telcom 2014-11-23 10:56:55