Search code examples
c++buildhyperlinksconswt

C++, error while linking. Building with scons


I try to run build example Wt project with scons, but for few hours I'm stuck. When I compile it with command:

g++ -o hello hello.cc -I/usr/local/include -L/usr/local/lib
  -lwthttp -lwt -lboost_random -lboost_regex
  -lboost_signals -lboost_system -lboost_thread -lboost_filesystem
  -lboost_program_options -lboost_date_time

(link to tutorial: http://www.webtoolkit.eu/wt/doc/tutorial/wt.html#_hangman) everything is ok, and I can run this simple example. But with my scons file:

env = Environment()

#       Add header search path
env.Append(CPPPATH = ['/usr/include', '/usr/local/include'])

#       Add compile-time flags
env.Append(CCFLAGS=[
#'-Wall','-g',
'-lwt', '-lwthttp',
'-lboost_random', '-lboost_regex', '-lboost_signals',
'-lboost_system', '-lboost_thread', '-lboost_filesystem',
'-lboost_program_options', '-lboost_date_time'
])

#       Add library search path
env.Append(LIBPATH = ['/usr/lib','/usr/local/lib', '/opt/lib'])

env.Program('hello',['exa.cc'])

#Program('exa.cc')
~                                        

I can't and get following errors: http://pastebin.com/Ft2b62ie . Thanks for any answer.

Lukasz.


Solution

  • The following SConstruct should work for you: The only difference is to place the libraries in the LIBS SCons Construction Variable and remove the '-l' from each, since its not necessary in SCons.

    (Notice this is basically the same answer as user2093113, but with the libraries correctly specified: https://stackoverflow.com/a/16555400/1158895)

    env = Environment()
    
    #       Add header search path
    env.Append(CPPPATH = ['/usr/include', '/usr/local/include'])
    
    #       Add compile-time flags
    #env.Append(CCFLAGS=['-Wall','-g'])
    
    # libraries to link against
    # Notice you dont need the '-l', since SCons is platform independent
    env.Append(LIBS=[
      'wt', 'wthttp',
      'boost_random', 'boost_regex', 'boost_signals',
      'boost_system', 'boost_thread', 'boost_filesystem',
      'boost_program_options', 'boost_date_time'
    ])
    
    #       Add library search path
    env.Append(LIBPATH = ['/usr/lib','/usr/local/lib', '/opt/lib'])
    
    # Compile and link the binary
    env.Program('hello',['exa.cc'])