宏在GCC工作,但在Solaris编译器失败
Macro in GCC works but in Solaris Compiler fails?
source: svn checkout svn://dev.exiv2.org/svn/trunk(最新版本:3020)
我的平台:Fedora 17 64位
下面的命令可以工作:
cmake -DCMAKE_CXX_FLAGS=-library=stlport4 -
DCMAKE_CXX_COMPILER=/opt/oracle/solarisstudio12.3/bin/CC -
DCMAKE_C_COMPILER=/opt/oracle/solarisstudio12.3/bin/cc .
但是之后当我做的时候,我得到了错误:
Scanning dependencies of target exiv2lib
[ 17%] Building CXX object src/CMakeFiles/exiv2lib.dir/asfvideo.cpp.o
cd /home/Wani/GSoC/exiv2-trunk/trunk/src && /opt/oracle/solarisstudio12.3/bin/CC -
DEXV_BUILDING_LIB -DEXV_HAVE_DLL -DEXV_LOCALEDIR="/usr/local/share/locale" -
DEXV_HAVE_STDINT_H -library=stlport4 -KPIC -I/home/Wani/GSoC/exiv2-trunk/trunk -
I/home/Wani/GSoC/exiv2-trunk/trunk/xmpsdk/include -o
CMakeFiles/exiv2lib.dir/asfvideo.cpp.o -c /home/Wani/GSoC/exiv2-
trunk/trunk/src/asfvideo.cpp
"/home/Wani/GSoC/exiv2-trunk/trunk/src/error.cpp", line 29: Error: Multiple declaration
for rcsId.
1 Error(s) detected.
error.cpp的内容:
28 #include "rcsid_int.hpp"
29 EXIV2_RCSID("@(#) $Id: error.cpp 2681 2012-03-22 15:19:35Z ahuggel $")
rcsid_int.hpp:
内容#ifndef RCSID_INT_HPP_
#define RCSID_INT_HPP_
#if !defined (EXIV2_RCSID)
#if defined(__clang__)
#define EXIV2_RCSID(id)
#elif defined(OS_SOLARIS)
#define EXIV2_RCSID(id)
{
inline const char* getRcsId(const char*) { return id ; }
const char* rcsId = getRcsId(rcsId);
}
#else
#define EXIV2_RCSID(id)
namespace {
inline const char* getRcsId(const char*) { return id ; }
const char* rcsId = getRcsId(rcsId);
}
#endif
#endif
#endif
如果我使用GCC编译相同的程序,它可以正常工作。
查看差异,因为Rev 3019在GCC和Solaris编译器中工作:http://dev.exiv2.org/projects/exiv2/repository/revisions/3020/diff?rev=3020&type=sbs
如何忽略Solaris编译器中的多个声明错误?
我已经计算了r3018和r3019中.cpp文件的预处理输出的差异:
2a3,6
> #30 "/home/Wani/exiv2-trunk/trunk/src/asfvideo.cpp"
> namespace { inline const char * getRcsId ( const char * ) { return "@(#) $Id$" ; }
const char * rcsId = getRcsId ( rcsId
> #30
> ) ; }
我在exiv2.org的wiki上发表了关于这个问题的评论,并提供了补丁解决了这个问题。
关键问题是Solaris Studio编译器不允许多行c++中的宏。我提供的补丁省略了这一点,因为它注释掉了完整的rcsId声明。据我所知,rcsid_int.hpp中的正确声明如下:
#if defined(__clang__) || (defined(OS_SOLARIS) && defined(__SUNPRO_CC))
#define EXIV2_RCSID(id)
#else
#define EXIV2_RCSID(id)
namespace {
inline const char* getRcsId(const char*) { return id ; }
const char* rcsId = getRcsId(rcsId);
}
#endif
这将导致预处理的源而不是包含rcsId字符串。
相关文章:
- C/C++编译器通常会删除重复的库吗
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- Win32编译器选项和内存分配
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 在线编译器中的分段C++没有打印消息
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- C/C++预处理器是否可以检测一些编译器选项
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 我需要知道编译器如何在cpp中使用析构函数
- 编译器如何区分std::vector的构造函数
- 不能在 Solaris 的最新编译器中使用带有新 c+11 标志的 xercesc
- Solaris 上的 GNU gcc/g++ 编译器版本,支持 C++11/14
- 如何使用 Solaris Studio 12.4 编译器构建 Boost V1.57
- 如何构建独立于编译器的C++库(适用于 Solaris Studio 和 gcc)
- 可以在windows上使用/模拟Solaris/Aix C/ c++编译器吗?
- 宏在GCC工作,但在Solaris编译器失败
- 对于 Solaris Studio 12.2 C++编译器来说,-xc99=all 的等效项是什么?