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.
.
My project setup is as follows (simplified for stack overflow purposes):
projectFolder/
├──bin/
│ ├─cpp/
│ └─Future Compiled Binary
│
├──cpp/
│ ├─SConscript
│ └─main.cpp
│
└──SConstruct
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
...
int main(void) {
...
}
# C++
env = Environment()
env.Append(CXXFLAGS = '-ldl')
print env["CXXFLAGS"]
srcFiles = ['main.cpp']
env.Program('../program', srcFiles)
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.