简体   繁体   中英

Why does scons ignore my CXXFlags in SConscript

Issue

When the command "scons" is run in the root directory, scons will eventually run the command "g++ -o bin/program bin/cpp/main.o" which will return the error:

"undefined reference to 'dlopen', 'dlerror', 'dlsym', 'dlerror'"

This undefined reference issue can be resolved with the '-ldl' compile argument, but for some reason, scons won't append it.

How do I get scons to add the '-ldl' argument to the g++ command.

.

Project Setup

My project setup is as follows (simplified for stack overflow purposes):

projectFolder/
 ├──bin/
 │  ├─cpp/
 │  └─Future Compiled Binary
 │
 ├──cpp/
 │  ├─SConscript
 │  └─main.cpp
 │
 └──SConstruct

main.cpp

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

...

int main(void) {

    ...

}

SConscript

# C++
env = Environment()
env.Append(CXXFLAGS = '-ldl')
print env["CXXFLAGS"]

srcFiles = ['main.cpp']
env.Program('../program', srcFiles)

SConstruct

SConscript('cpp/SConscript', variant_dir='bin/cpp')

Don't use CXXFLAGS to link libraries. You should do this:

env.Program('../program', srcFiles, LIBS=['dl'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM