Search code examples
c++cross-compilingclang++sconsraylib

SCons: ld cannot find standard libraries


I'm developing a game with raylib using SCons for building. I'm using Clang to cross compile from Ubuntu (in WSL) to Windows. My project directory contains a lib directory with the raylib binaries and an include directory with the raylib headers. When I run SCons I get this output:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang++ -o main.o -c -mwindows --target=x86_64-w64-windows-gnu -static -static-libgcc -static-libstdc++ -Iinclude main.cpp
clang: warning: argument unused during compilation: '-mwindows' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-static-libgcc' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-static-libstdc++' [-Wunused-command-line-argument]
clang++ -o tiled_test.exe main.o -Llib -lraylib -lopengl32 -lgdi32 -lwinmm
/bin/ld: cannot find -lopengl32
/bin/ld: cannot find -lgdi32
/bin/ld: cannot find -lwinmm
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [tiled_test.exe] Error 1
scons: building terminated because of errors.

ld can't find opengl32, gli32, and winmm.

My SConstruct file:

import os

LIBS=['raylib', 'opengl32', 'gdi32', 'winmm']
LIBPATH='./lib'
CCFLAGS='-mwindows --target=x86_64-w64-windows-gnu -static -static-libgcc -static-libstdc++'

env = Environment(CXX='clang++', CPPPATH='./include')
env['ENV']['TERM'] = os.environ['TERM'] # Colored output

env.Program('tiled_test.exe', 'main.cpp', LIBS=LIBS, LIBPATH=LIBPATH, CCFLAGS=CCFLAGS)

When I run Clang++ directly it works perfectly.

clang++ main.cpp -o tiled_test.exe -Iinclude -Llib -mwindows --target=x86_64-w64-windows-gnu -static -static-libgcc -static-libstdc++ -lraylib -lopengl32 -lgdi32 -lwinmm

Solution

  • I found the answer to my problem. According the this by default SCons doesn't use the shell's PATH. The user needs to add it to the environment.

    My fixed SConstruct file:

    import os
    
    LIBS=['raylib', 'opengl32', 'gdi32', 'winmm']
    LIBPATH='./lib'
    CCFLAGS='-static --target=x86_64-w64-windows-gnu'
    LINKFLAGS = '-mwindows --target=x86_64-w64-windows-gnu -static-libgcc -static-libstdc++'
    
    env = Environment(CXX='clang++', CPPPATH='./include', tools = ['mingw'], ENV = {'PATH' : os.environ['PATH']})
    env['ENV']['TERM'] = os.environ['TERM'] # Colored output
    
    env.Program('tiled_test.exe', 'main.cpp', LIBS=LIBS, LIBPATH=LIBPATH, CCFLAGS=CCFLAGS, LINKFLAGS=LINKFLAGS)