首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GCC中的宏可以工作,但在Solaris编译器中却失败了?

GCC中的宏可以工作,但在Solaris编译器中却失败了?
EN

Stack Overflow用户
提问于 2013-04-18 19:19:22
回答 1查看 528关注 0票数 0

来源: svn checkout svn://dev.exiv2.org/svn/trunk (最新版本: 3020)

我的平台: Fedora 17 64位

以下命令起作用:

代码语言:javascript
复制
cmake -DCMAKE_CXX_FLAGS=-library=stlport4 -    
DCMAKE_CXX_COMPILER=/opt/oracle/solarisstudio12.3/bin/CC -        
DCMAKE_C_COMPILER=/opt/oracle/solarisstudio12.3/bin/cc .

但在那之后,当我真的犯了错误时,我得到了错误:

代码语言:javascript
复制
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的内容:

代码语言:javascript
复制
28 #include "rcsid_int.hpp"
29 EXIV2_RCSID("@(#) $Id: error.cpp 2681 2012-03-22 15:19:35Z ahuggel $")

Rcsid_int.hpp的内容:

代码语言:javascript
复制
#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编译相同的程序,它可以正常工作。

请参阅不同之处,因为Rev3019可以在GCC和Solaris编译器中工作:http://dev.exiv2.org/projects/exiv2/repository/revisions/3020/diff?rev=3020&type=sbs

如何在Solaris编译器中忽略多个声明错误?

我已经计算了r3018和r3019中.cpp文件的预处理输出的差异:

代码语言:javascript
复制
 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
 > ) ; } 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-19 20:18:24

我在exiv2.org的wiki上发表了关于这个问题的评论,并提供了解决这个问题的补丁。

关键问题是Solaris Studio编译器不允许在C++中使用多行宏。我提供的修补程序省略了这一点,因为它注释掉了整个rcsId声明。

据我所知,rcsid_int.hpp中的正确声明如下:

代码语言:javascript
复制
#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字符串。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16081514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档