标签: gcc4

为官方iPhone SDK交叉编译基于Autotools的库

背景

我正在编写一个针对几种不同手机的程序,包括iPhone.该计划取决于几个第三方图书馆.我很难为iPhone和iPhone模拟器交叉编译这些第三方库.这些库包括Apache Portable Runtime和GNUTLS,以及它们的依赖项.我希望构建的库最后以前缀"/opt/iphone-3.1","/ opt/iphone-3.0","/ opt/iphone-2.2.1","/ opt /iphone-modules3.1 "和"/opt/iphone-simulator-3.0"分别.

为了使交叉编译过程易于重复,我正在创建脚本来为每个目标平台调用"configure"脚本("iphone3.1-configure","iphone3.0-configure","iphone2.2.1" -configure","iphonesim3.1-configure"和"iphonesim3.0-configure").这是我遇到麻烦的地方.

我正在使用Mac OS X 10.6 Snow Leopard计算机和官方Xcode 3.2 + iPhone SDK 3.1.

状态

我目前有以下"iphone3.1-configure"脚本:

#! /bin/bash

#
# Program  : iphone3.1-configure
# Author   : Michael Aaron Safyan
# Synopsis :
#            This program runs the "configure" script generated by the
#            GNU Autotools in order to cross-compile thirdparty libraries
#            for the iPhone 3.1 SDK. Run this script while in a directory
#            containing an autotools "configure" script. Once run, …

iphone autotools cross-compiling gcc4

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

强制GCC 4.x将-Wreturn-type视为错误而不启用-Werror?

假设我们有以下代码:

#if !defined(__cplusplus)
#  error This file should be compiled as C++
#endif

#include <stdio.h>
#include <string>

//#define USE_CXX_CLASS
#ifdef USE_CXX_CLASS
class SomeClass
{
public:
    SomeClass() {}
    ~SomeClass() {}
    std::string GetSomeString()
    {
        // case #1
    }
};
#endif // USE_CXX_CLASS

int foo()
{
    // case #2
}

int
main (int argc, char *argv[])
{
    (void)argc;
    (void)argv;
#ifdef USE_CXX_CLASS
    SomeClass someInstance;
    someInstance.GetSomeString();
#endif // USE_CXX_CLASS
    foo();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

并且假设它是使用选项从GCC版本4.2.1编译C++编译器(而不是C编译器)-Wreturn-type -Werror=return-type.如果上面的代码是按原样编译而没有先取消//#define USE_CXX_CLASS上面的行,那么你会看到一个警告但没有错误:

.../gcc-4.2.1/bin/g++   -g    -fPIC …
Run Code Online (Sandbox Code Playgroud)

c++ gcc return-value gcc-warning gcc4

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

用于发布版本的dSYM文件

.dSYM资源是否包含除DWARF信息之外的任何其他信息?我创建了一个应用程序的发布版本.现在,如果我运行dwarfdump它,它说可执行文件没有DWARF信息(说它是"空"),这是我所期望的.但是,如果我然后运行dsymutil它,它会创建非空符号文件.这些是二进制文件,所以我不知道它们是什么.任何人都可以启发我吗?这些文件有没有观众?

dwarf symbolicate gcc4 ios

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

我可以使用Macports的GCC编译通用代码吗?

由于Apple不支持GCC 4.6或GCC 4.7,我刚刚切换到MacPorts的GCC 4.6/4.7版本.但是,我在"通用"架构中构建代码时遇到了问题.

传统上,我会g++ -arch i386 -arch x86_64 ...为至少i386/x86_64架构编译我的二进制文件.我做了一些搜索,并意识到-arch选项只有apple的编译器支持.所以当然它不适用于Macports.我能做的最好的事情是使用-m32/ -m64options来指定我想要的架构.但是,这只会生成i386或x86_64格式的二进制文件.我真正想要的是在两个架构(Universal)中获得二进制文件,就像使用原始GCC编译器一样.

这是不支持还是已知问题?我已经尝试了整晚在Google上寻找答案,但我没有得到任何有用的东西.所以我只是开始怀疑我是否是唯一有这个问题的人,而且我错过了让它发挥作用的重要事项?真的很感激,如果有人能给我一些建议.

BTW.我已经安装了gcc46 +universal变体,但除了为每个体系结构编译单独的二进制文件之外,它并没有产生任何真正的通用.

兴.

macos macports gcc4

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

如何让gcc使用march = native作为默认值?

有没有办法更改specs文件,以便-march=native在命令行中没有指定任何内容时它将通过?

默认规范文件中的相关内容是:

*cc1:
%(cc1_cpu)

*cc1_cpu:
%{march=native:%>march=native %:local_cpu_detect(arch)   %{!mtune=*:%>mtune=native %:local_cpu_detect(tune)}} %{mtune=native:%>mtune=native %:local_cpu_detect(tune)}
Run Code Online (Sandbox Code Playgroud)

我不确定规格如何运作.简单地指定-march=native之前或之后%(cc1_cpu)不起作用.不过,此行确实需要的效果,因为如果我把GCC会报告错误-something_wierd,而不是-march=native.

我注意到的另一件事是,如果我%{march=i386:-something_wierd}之前%(cc1_cpu),gcc报告错误,所以看起来-march=i386总是传入,如果没有指定,所以有没有办法区分指定的任何内容和-march=i386specs文件?

顺便说一下,该怎么%>办?好像它没有在文档中指定.

我正在使用MinGW gcc-4.6.2.

gcc gcc4

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

gcc4模板错误或更可能是id10t错误

以下代码在Visual Studio下编译得很好,但gcc 4.6.2或4.7都无法处理它.它似乎是有效的,但gcc似乎无法解决const和非const参数之间的区别.这可能是编译器错误吗?

struct CReadType{};
struct CWriteType{};

template<typename ReadWriteType, typename T> 
struct AddPkgrConstByType {}; 
template<typename T> 
struct AddPkgrConstByType<CReadType, T> {
   typedef T type;
};    
template<typename T>
struct AddPkgrConstByType<CReadType, const T> {
    typedef T type;
};
template<typename T>
struct AddPkgrConstByType<CWriteType, T> {
    typedef T const type;
};

template<typename Packager, typename T>
struct AddPkgrConst : public AddPkgrConstByType<typename Packager::CReadWriteType, T> {
};

template<typename Packager, typename T>
inline bool Package( Packager* ppkgr, T* pt ) 
{
    return true;
}

template<typename Packager>
inline bool Package( …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction gcc templates gcc4

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

g ++警告:永远不会被执行

继承了一个C++项目.我正在使用gcc 4.1.2通过makefile在RHEL 5.5中构建.该项目是巨大的(数百个文件),一般来说代码非常好.但是,在编译期间,我经常会收到GCC警告:

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In constructor ‘std::allocator<_Alloc>::allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:97: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:97: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: In constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:65: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:105: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: In destructor ‘__gnu_cxx::new_allocator<_Tp>::~new_allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:72: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In copy constructor ‘std::allocator<_Alloc>::allocator(const std::allocator<_Alloc>&) [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:100: warning: will never be …
Run Code Online (Sandbox Code Playgroud)

c++ gcc-warning gcc4

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

函数返回值的生命周期是多少?

我阅读了return函数调用之间的值,
并尝试使用以下代码片段:

/* file structaddr.c */
#include <stdio.h>    
#define MSIZE 10

struct simple
{   
    char c_str[MSIZE];
};
struct simple xprint(void)
{
    struct simple ret = { "Morning !" };
    return ret;
}
int main(void)
{   
    printf("Good %s\n", xprint().c_str);    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译代码时没有错误和警告.
使用GCC 4.4.3(Ubuntu 4.4.3-4ubuntu5.1)Visual C++编译器进行测试.

 gcc -m32 -std=c99 -Wall -o test  structaddr.c  
 cl -W3 -Zi -GS -TC -Fetest structaddr.c
Run Code Online (Sandbox Code Playgroud)

输出:
早上好!

我对结果感到有些困惑.
代码写得正确吗?

我的问题 :

  • 函数return值的可见性是什么(上例中的数组 struct),以及如何正确访问它们?

  • 哪里结束了一生的return价值?

c gcc visual-c++ gcc4

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

链接多个C源文件

我在安装了GCC 4.4.5的gentoo linux上.我可以使用gcc main.c -o main编译和链接这样的程序而没有任何错误,并且命令./main正确返回结果.

[main.c] 
#include <math.h>
#include <stdio.h>
int main(void)
{
    double c = ceil(2.5);
    printf("The ceil of 2.5 is %f\n", c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,当我将ceil的调用放入另一个源文件时,就会出现问题.

[calc.h]
#ifndef _CALC_H_
#define _CALC_H_
double myceil(double n);
#endif

[calc.c]
#include <math.h>
#include "calc.h"
double myceil(double n)
{
    return ceil(n);
}

[main1.c]
#include <stdio.h>
#include "calc.h"
int main(void)
{
    double c = myceil(2.5);
    printf("The ceil of 2.5 is %f\n", c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用命令gcc …

c linker gentoo gcc4

4
推荐指数
1
解决办法
295
查看次数

G++ 4.5.0 中的 std::forward_as_tuple

我对该功能有迫切的需求std::forward_as_tuple,但仅限于使用 GCC 4.5.0(我知道这是一个糟糕的情况,但它会为我解决很多问题,所以请把尖刻的评论保留在最低限度)。该<tuple>头似乎并不包含函数(因为它应该),所以我的问题是:

  1. 它是否隐藏在其他标题中?(这种情况以前发生过,但很难确定。)
  2. 是否可以推出自己的实现?这就是:这是可实现与C ++ 11的部分在GCC 4.5.0执行?如果有人真的知道如何做到这一点,那就再好不过了。

c++ tuples gcc4 perfect-forwarding c++11

4
推荐指数
1
解决办法
562
查看次数