【问题标题】:Why does scons ignore my CXXFlags in SConscript为什么 scons 在 SConscript 中忽略我的 CXXFlags
【发布时间】:2018-11-14 06:08:04
【问题描述】:

问题

当在根目录下运行“scons”命令时,scons最终会运行“g++ -o bin/program bin/cpp/main.o”命令返回错误:

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

这个未定义的引用问题可以通过 '-ldl' 编译参数解决,但由于某种原因,scons 不会附加它。

如何让 scons 将“-ldl”参数添加到 g++ 命令。

.

项目设置

我的项目设置如下(为堆栈溢出而简化):

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)

S构造

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

【问题讨论】:

    标签: c++ g++ scons


    【解决方案1】:

    不要使用 CXXFLAGS 链接库。你应该这样做:

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

    【讨论】:

      猜你喜欢
      • 2011-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 2020-06-18
      相关资源
      最近更新 更多