标签: compiler-options

如何根据编译器类型在SConstruct for C编译器中设置选项?

我需要为C编译器设置其他选项,例如添加标志以打开所有警告,具体取决于编译器的类型.例如,我应该使用MSVC

env.Append(CPPFLAGS = "/Wall")
Run Code Online (Sandbox Code Playgroud)

但对于mingw(gcc)我需要使用:

env.Append(CCFLAGS = "-Wall") 
Run Code Online (Sandbox Code Playgroud)

我怎样才能以scons的方式做到这一点?

c compiler-construction scons compiler-options

5
推荐指数
1
解决办法
3188
查看次数

Google协议缓冲交叉编译

我使用Google协议缓冲区的问题有两个部分,一个是关于编译器选项,另一个是交叉编译.构建机器是Power6,64bit; 主机是PowerPC450,32bit.Gcc 4.1.2.

第一个问题是关于编译器选项:

我正在尝试在需要交叉编译的PowerPC机器上安装Google协议缓冲区.构建机器是Power6,64bit; 主机是PowerPC450,32bit.首先,我尝试直接在构建机器上安装,并提供选项告诉编译器使用哪个:

./configure --prefix=/home/where_to_install --host=powerpc-bgp-linux
Run Code Online (Sandbox Code Playgroud)

然后制作,制作检查,安装,一切都很好.我认为我已经指定了主机,它应该包含编译需要知道的足够信息.当我尝试编译我的代码时

/bgsys/drivers/ppcfloor/gnu-linux/powerpc-bgp-linux/bin/g++ -g -zmuldefs -Xlinker -I/home/somewhere_installed/include $sourceFile -o $fileName -L/home/somewhere_installed/lib -lz -lstdc++ -lrt -lpthread -lm -lc -lprotobuf -lprotoc msg.pb.cc
Run Code Online (Sandbox Code Playgroud)

我得到了错误:

g++: unrecognized option '-zmuldefs'
In file included from zht_util.h:20,
                 from hash-phm.cpp:9:
meta.pb.h:9:42: error: google/protobuf/stubs/common.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)

并且没有发现很多关于common.h中的变量的错误.

我知道这是因为编译器无法识别选项-zmuldefs,因此无法找到确实存在的文件common.h.我用Google搜索并没有得到任何明确的想法.如何让编译器可以使用该选项或者可以找到该文件?或者我的编译命令有问题吗?


第二个问题是关于交叉编译.Google协议缓冲区的自述文件不清楚交叉编译的准确程度.它说我必须使用--with-protoc = protoc告诉配置使用哪个,好的,但在此之前我必须为主机安装一个副本.我首先使用该命令为主机安装副本

./configure --prefix=/home/where_to_install/built --host=powerpc-bgp-linux
Run Code Online (Sandbox Code Playgroud)

然后制作,安装.

然后用下面的交叉编译使用与主机相同的编译器:

./configure --prefix=/home/tonglin/Installed/built_3 CC=/bgsys/drivers/ppcfloor/gnu-linux/bin/powerpc-bgp-linux-gcc CXX=/bgsys/drivers/ppcfloor/gnu-linux/bin/powerpc-bgp-linux-g++ --host=powerpc-bgp-linux --with-protoc=/home/where_already_Installed/built/bin/protoc
Run Code Online (Sandbox Code Playgroud)

然后制造并得到错误:

很多编译信息... blabla .....

collect2: ld returned 1 exit status
make[3]: *** [protoc] Error 1
make[3]: …
Run Code Online (Sandbox Code Playgroud)

compiler-errors cross-compiling compiler-options

5
推荐指数
1
解决办法
1万
查看次数

C++中用于将默认变量类型设置为int的任何选项

是否有任何选项可以省略变量类型将变量类型设置 int为要在linux中使用g ++编译器编译的c ++代码.

    const bufLen = 2000;
Run Code Online (Sandbox Code Playgroud)

solaris中的编译很顺利(因为我正在从solaris移植到linux).

还有一件事,我无法控制文件,因为它是由一些解析器生成的(由某些第三方以二进制形式提供)

由于我无法更改c ++文件(因为它是在编译之前每次生成的),我需要一些选项(g ++),所以我可以在编译期间包含以抑制/解决错误:

error: ISO C++ forbids declaration of `bufLen` with no type
Run Code Online (Sandbox Code Playgroud)

编辑:

INFO:我正在使用的选项-c -fPIC -Wno-deprecated -m32 -O2 -ffriend-injection -g

是否有任何选项会给我带来麻烦(或影响其他)?


提前致谢

c++ g++ compiler-options

5
推荐指数
1
解决办法
618
查看次数

警告类成员自我初始化

看看这段C++代码:

class Foo
{
    int a;

    public: Foo(int b): a(a) {}
};
Run Code Online (Sandbox Code Playgroud)

显然,开发商意味着初始化ab而非a本身,这是一个相当困难的现场错误.

Clang ++会警告这个可能的错误,而GCC不会,即使启用了其他警告:

$ clang++ -c init.cpp 
init.cpp:5:27: warning: field is uninitialized when used here [-Wuninitialized]
    public: Foo(int b): a(a) {}
                        ^

$ g++ -Wall -Wuninitialized -Winit-self -c init.cpp 
$
Run Code Online (Sandbox Code Playgroud)

有没有机会为g ++启用相同的输出?

c++ gcc warnings initialization compiler-options

5
推荐指数
1
解决办法
1849
查看次数

分别告诉gcc诊断

我在解释gcc(4.8.2)警告和错误时遇到问题.更准确地说,很难分辨出一个问题的结束和另一个问题的开始.我只有控制台访问构建机器,因此不能使用IDE.

我真的需要能够快速区分个别问题.有没有办法让GCC在不同的诊断消息之间插入一些内容?

这是我得到的示例输出:

/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp: In member function ‘virtual bool xmodel::Core::DataItemCollection::tryAdditionalItemRegistration(std::shared_ptr<xmodel::Core::IDataItem>) const’:
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const std::_Placeholder<1>&, const QUuid&)’
       , std::bind(&IDataItemCollectionScope::findItemById, _1, id)
                                                                  ^
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: note: candidates are:
In file included from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/bits/stl_algo.h:66:0,
                 from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/algorithm:62,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qglobal.h:68,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qatomic.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qhash.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/QHash:1,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/ItemId.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItem.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/DataItemDescriptor.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:9:
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1655:5: note: template<class _Func, class ... _BoundArgs> typename std::_Bind_helper<std::__or_<std::is_integral<typename std::decay<_Tp>::type>, std::is_enum<typename std::decay<_Tp>::type> >::value, _Func, _BoundArgs …
Run Code Online (Sandbox Code Playgroud)

gcc compiler-errors compiler-warnings compiler-options

5
推荐指数
2
解决办法
531
查看次数

有人能举例说明javac的-implicit选项是如何工作的吗?

在shell命令提示符下,如果我输入javac -help,它会告诉我该-implicit选项指定"...是否为隐式引用的文件生成类文件".有两种选择-implicit: none或者class.

首先,使用-implicit:none和不使用 - implicit选项有什么区别?

其次,关于我的问题标题,我希望提供的示例可以帮助我理解隐式引用的文件是什么.非常感谢.

java compiler-options

5
推荐指数
1
解决办法
3398
查看次数

如何使用autotools设置特定于编译器的标志

我们使用autotools作为构建基础架构,我们使用clang和gcc作为编译器.最近我们遇到了需要的gcc警告

--param max-vartrack-size=100000000
Run Code Online (Sandbox Code Playgroud)

沉默(没有完全禁用gcc的vartracking).Clang不接受该选项并生产

argument unused during compilation: '--param max-vartrack-size=100000000'
Run Code Online (Sandbox Code Playgroud)

为了保持沉默,铿锵需要

-Qunused-arguments
Run Code Online (Sandbox Code Playgroud)

并在gcc下产生错误:

unrecognized command line option ‘-Qunused-arguments’
Run Code Online (Sandbox Code Playgroud)
  1. configure.ac在选择编译器之后,定义特定于编译器的标志的最佳方法是什么,例如AC_PROG_CXX?我们AC_SUBST(AM_CXXFLAGS)所以我想我会在其中扩展编译器特定变量AM_CXXFLAGS.

  2. Makefile.am一个编译器中启用每个目标选项的正确方法是什么?我在考虑:

    if HAVE_GCC
        SPECIFIC_CXXFLAGS = --param...
    endif
    if HAVE_CLANG
        SPECIFIC_CXXFLAGS = -Q...
    endif
    libfoo_la_CXXFLAGS = $(AM_CXXFLAGS) $(SPECIFIC_CXXFLAGS)
    
    Run Code Online (Sandbox Code Playgroud)

但我需要HAVE_*从configure.ac中取代变量.不要AC_PROG_CXX/CC或许已经定义了这样的事情?

gcc autotools clang compiler-options

5
推荐指数
1
解决办法
1684
查看次数

检测(无意义)分配给临时对象

当您尝试分配给临时对象时,是否有任何编译器选项允许您收到警告?

例子:

struct S {
    S op() { return S(); }
};

int main() {
    S s;
    s.op() = s; // assign to temporary. Wants to warn here.
}
Run Code Online (Sandbox Code Playgroud)

我知道你可以声明opas的返回类型const来防止这种情况,但现在我感兴趣的只是编译器选项。

您可以使用任何流行的现代编译器。

c++ compiler-warnings compiler-options temporary-objects

5
推荐指数
1
解决办法
177
查看次数

获取Python的LIB路径

我看到那INCLUDE条路是sysconfig.get_path('include')

但我看不到有任何类似的价值LIB

NumPy 直接os.path.join(sys.prefix, "libs")Windows中那样对其进行硬编码,否则(在Windows中get_config_var('LIBDIR')没有记录和丢失)。

还有更多受支持的方法吗?

python python-c-api compiler-options

5
推荐指数
1
解决办法
619
查看次数

没有记录 clang 编译器选项?

为了使用 Xcode 将编译器选项迁移到 ARM,我正在寻找有关 clang c++ 编译器/链接器选项的综合文档。我能得到的最接近的是这个页面,但是:

  1. 许多选项不作说明,如-arch-arch_errors_fatal-sub_umbrella等等。
  2. 有在Xcode命令行选项中丢失了这个文档,例如-Wno-four-char-constants-Wshorten-64-to-32等等。

有什么地方可以找到对每个选项都有详尽解释的完整文档吗?请注意,我不需要在这里作为示例给出的选项的含义,仅用于综合参考。

c++ migration xcode clang compiler-options

5
推荐指数
1
解决办法
306
查看次数