无法编译任何C ++程序;错误:未知类型名称'uint8_t' [英] Cannot compile any C++ programs; error: unknown type name 'uint8_t'

查看:2083
本文介绍了无法编译任何C ++程序;错误:未知类型名称'uint8_t'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是不是简单的印刷错误.我在下面的日志中打了一个错字,我已经纠正了,但是问题仍然存在.

一次尝试以下操作后,我一次错误地使用了gcc而不是g ++. g ++之前存在问题,现在已经存在.

我目前在MacOS High Sierra盒子上.我最近将许多文件从MacBook Air移到了这台机器上,包括我认为都是Xcode的垃圾文件.现在,当我尝试编译一个非常简单的C ++程序时:

#include <iostream>

int main()
{
    // VAR_DEC
    int a = 4;
    // VAR_MANIP
    a = a*2;
    // VAR_PRINT
    std::cout << a << std::endl;
    return 0;
}

我收到以下荒谬错误:

jrfarah@Josephs-MBP: [config_file_script] $ g++ test.cpp -o test
In file included from test.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:470:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view:171:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__string:56:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:640:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/memory:629:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/typeinfo:61:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/exception:82:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:86:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:94:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
/usr/include/sys/resource.h:196:2: error: unknown type name 'uint8_t'
        uint8_t  ri_uuid[16];
        ^
/usr/include/sys/resource.h:197:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/usr/include/sys/resource.h:198:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/usr/include/sys/resource.h:199:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/usr/include/sys/resource.h:200:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
/usr/include/sys/resource.h:201:2: error: unknown type name 'uint64_t'
        uint64_t ri_pageins;
        ^
/usr/include/sys/resource.h:202:2: error: unknown type name 'uint64_t'
        uint64_t ri_wired_size;
        ^
/usr/include/sys/resource.h:203:2: error: unknown type name 'uint64_t'
        uint64_t ri_resident_size;
        ^
/usr/include/sys/resource.h:204:2: error: unknown type name 'uint64_t'
        uint64_t ri_phys_footprint;
        ^
/usr/include/sys/resource.h:205:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_start_abstime;
        ^
/usr/include/sys/resource.h:206:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_exit_abstime;
        ^
/usr/include/sys/resource.h:210:2: error: unknown type name 'uint8_t'
        uint8_t  ri_uuid[16];
        ^
/usr/include/sys/resource.h:211:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/usr/include/sys/resource.h:212:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/usr/include/sys/resource.h:213:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/usr/include/sys/resource.h:214:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
/usr/include/sys/resource.h:215:2: error: unknown type name 'uint64_t'
        uint64_t ri_pageins;
        ^
/usr/include/sys/resource.h:216:2: error: unknown type name 'uint64_t'
        uint64_t ri_wired_size;
        ^
/usr/include/sys/resource.h:217:2: error: unknown type name 'uint64_t'
        uint64_t ri_resident_size;
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

我尝试安装并重新安装与该问题有关的所有内容,例如gccg++ccbrew,Xcode,command-line-tools等.尝试了以下页面上的所有建议:

等等,但是那些总结得很好.这些解决方案均无效.

我认为最后一个是最可能的解决方案. (如果您在页面上搜索未知",则会看到此修复程序.)根据开发人员的说法:

修复:从标题搜索路径"构建设置中删除/opt/local/include/**和/opt/local/lib/**.将它们替换为指向所需包含目录的更具体的路径.在我的特定情况下,这意味着将它们替换为/opt/local/include/glib-2.0/opt/local/lib/glib-2.0/include/opt/local/include/.重新启动并运行!

但是,我没有安装Xcode,仅安装了命令行开发人员工具.因此,我没有一种简单的方法来访问标题搜索路径"构建设置,因此,我无法尝试他的解决方案.

我正在寻找一种解决方案,最好是不需要我安装整个操作系统的解决方案.另外,如果有人可以指导我找到构建设置文件,我将不胜感激.

解决方案

很明显,您使系统的GCC安装感到厌烦.请注意,GCC是编译器的套件,而 G ++ 是C ++前端.软件包管理器通常有一个单独的名为gcc-g++的软件包,但是,从源代码进行编译时,您只需执行--enable-languages=c,c++.现在,如果重新安装XCode不能解决问题(您应该已经做到了,如果占用太多空间",只需删除它),则可以尝试从源代码编译GCC.改编自 GNU Wiki :

  • 首先,从此处

  • tar zxvf gcc*

  • 解压缩
  • cd gcc*然后./contrib/download_prerequisites

  • 执行非源构建:mkdir build && cd build

  • ../gcc*/configure --prefix=$HOME/gcc-install --enable-languages=c,c++

  • makemake install

现在,只需将$HOME/gcc-install/bin添加到您的路径中,您就可以使用了.

EDIT2: The problem was NOT a simple typographical error. I made a typo in the logs below, which I corrected, but the problem was still there.

EDIT: I mistakenly ran with gcc instead of g++, once, after attempting below. The problem was there before with g++ and it is there now.

I am currently on a MacOS High Sierra box. I recently moved a lot of files from a MacBook Air to this machine, including what I assume were all of Xcode's junk. Now, when I try to compile a very simple C++ program:

#include <iostream>

int main()
{
    // VAR_DEC
    int a = 4;
    // VAR_MANIP
    a = a*2;
    // VAR_PRINT
    std::cout << a << std::endl;
    return 0;
}

I get the following ridiculous error:

jrfarah@Josephs-MBP: [config_file_script] $ g++ test.cpp -o test
In file included from test.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:470:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view:171:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__string:56:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:640:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/memory:629:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/typeinfo:61:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/exception:82:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:86:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:94:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
/usr/include/sys/resource.h:196:2: error: unknown type name 'uint8_t'
        uint8_t  ri_uuid[16];
        ^
/usr/include/sys/resource.h:197:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/usr/include/sys/resource.h:198:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/usr/include/sys/resource.h:199:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/usr/include/sys/resource.h:200:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
/usr/include/sys/resource.h:201:2: error: unknown type name 'uint64_t'
        uint64_t ri_pageins;
        ^
/usr/include/sys/resource.h:202:2: error: unknown type name 'uint64_t'
        uint64_t ri_wired_size;
        ^
/usr/include/sys/resource.h:203:2: error: unknown type name 'uint64_t'
        uint64_t ri_resident_size;
        ^
/usr/include/sys/resource.h:204:2: error: unknown type name 'uint64_t'
        uint64_t ri_phys_footprint;
        ^
/usr/include/sys/resource.h:205:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_start_abstime;
        ^
/usr/include/sys/resource.h:206:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_exit_abstime;
        ^
/usr/include/sys/resource.h:210:2: error: unknown type name 'uint8_t'
        uint8_t  ri_uuid[16];
        ^
/usr/include/sys/resource.h:211:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/usr/include/sys/resource.h:212:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/usr/include/sys/resource.h:213:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/usr/include/sys/resource.h:214:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
/usr/include/sys/resource.h:215:2: error: unknown type name 'uint64_t'
        uint64_t ri_pageins;
        ^
/usr/include/sys/resource.h:216:2: error: unknown type name 'uint64_t'
        uint64_t ri_wired_size;
        ^
/usr/include/sys/resource.h:217:2: error: unknown type name 'uint64_t'
        uint64_t ri_resident_size;
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

I've tried installing and reinstalling everything I could think of related to the problem, such as gcc, g++, cc, brew, Xcode, command-line-tools, etc. I've also tried all the suggestions on the following pages:

and more, but those summarize it pretty well. None of the solutions have worked.

I think the last one has the most likely solution. (If you search for "unknown" on the page you'll see the fix.) According to the developer:

Fix: Remove /opt/local/include/** and /opt/local/lib/** from the "Header Search Paths" build settings. Replace them with much more specific paths to the desired include directories. In my particular case, this meant replacing them with /opt/local/include/glib-2.0 /opt/local/lib/glib-2.0/include /opt/local/include/. It's up and running again!

However, I didn't install Xcode, I only installed the command line developer tools. Therefore, I don't have an easy way to access the "Header Search Paths" build settings, and thus, I can't try out his solution.

I am looking for a solution to this problem, preferably one that doesn't require me installing the entire OS. Alternatively, if someone could kindly guide me through finding the build settings file, I would be very grateful.

解决方案

It's fairly obvious that you borked your system GCC installation. Please note that GCC is a suite of compilers and that G++ is the C++ front-end. Package managers often have a separate package called gcc-g++, however, when compiling from source, you simply do --enable-languages=c,c++. Now if reinstalling XCode doesn't resolve the problem (you should've already done this, if "it takes up too much space" just remove it), then you can try compiling GCC from source. Adapted from the GNU wiki:

  • First, grab your desired GCC tar ball from here

  • Untar it with tar zxvf gcc*

  • cd gcc* then ./contrib/download_prerequisites

  • Do an out of source build: mkdir build && cd build

  • ../gcc*/configure --prefix=$HOME/gcc-install --enable-languages=c,c++

  • make and make install

Now just add $HOME/gcc-install/bin to your path and you should be good to go.

这篇关于无法编译任何C ++程序;错误:未知类型名称'uint8_t'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆