今天我遇到了链接我编译的cuda东西的问题.
我有一个最新的debian测试w/2.6.32-3-amd64.
我整天在我的代码上工作.不时编译.没问题.但是经过一次小的代码更改后我得到了以下错误:
gcc -o pa CUDA.o histogram256.o histogram64.o main.o -lrt -lm -lcudart -I. -I/data/cuda/include -I/data/cuda/C/common/inc -L/data/cuda/lib64
/usr/bin/ld: main.o: undefined reference to symbol 'std::basic_ifstream<char, std::char_traits<char> >::close()@@GLIBCXX_3.4'
/usr/bin/ld: note: 'std::basic_ifstream<char, std::char_traits<char> >::close()@@GLIBCXX_3.4' is defined in DSO /usr/lib64/libstdc++.so.6 so try adding it to the linker command line
/usr/lib64/libstdc++.so.6: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我改回了代码,但错误仍然存在.
lib就是应该存在的地方.(/ usr/lib64链接到/ usr/lib)
ldd /usr/lib/libstdc++.so.6
linux-vdso.so.1 => (0x00007fff31fff000)
libm.so.6 => /lib/libm.so.6 (0x00007f15f625a000)
libc.so.6 => /lib/libc.so.6 (0x00007f15f5ef9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f15f680d000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 …Run Code Online (Sandbox Code Playgroud) 可能重复:
GCC链接器找不到标准库?
我试图搞砸我在假期里得到的这本C++书,我来自对python的有限理解,所以这些东西对我来说真的很奇怪.
我从第一课中输入了这段代码到我的文本编辑器中并将其保存为.cpp文件.
#include <iostream>
int main()
{
std::cout << "Enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2
<< " is " << v1 + v2 << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试编译它时,我的终端给出了这个疯狂的输出,是怎么回事?
Raymond-Weisss-MacBook-Pro:c++ Raylug$ gcc prog2.cpp
Undefined symbols for architecture x86_64:
"std::basic_istream<char, std::char_traits<char> >::operator>>(int&)", referenced from:
_main in cckdLEun.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> …Run Code Online (Sandbox Code Playgroud) 我只是想设置一个简单的递归结构而不需要太多的C知识(必须以某种方式学习)
这是我的make编译行
g++ -o cs533_hw3 main.c
Run Code Online (Sandbox Code Playgroud)
这是我的代码
typedef struct Node Node;
struct Node
{
int texture;
float rotation;
Node *children[2];
};
Node rootNode;
rootNode.rotation
Run Code Online (Sandbox Code Playgroud)
这是我在最后一行的错误
error: 'rootNode' does not name a type
Run Code Online (Sandbox Code Playgroud) 我是c ++的新手,我想编译我的测试程序.
我现在有3个文件"main.cpp""parse.cpp""parse.h"
我怎么能用一个命令编译它?
这个代码用g ++编译好,但在用gcc编译时会抛出链接器错误.这些错误的原因是什么?
$ g++ traits2.cpp
$ gcc traits2.cpp
/tmp/ccI7CNCY.o: In function `__static_initialization_and_destruction_0(int, int)':
traits2.cpp:(.text+0x36): undefined reference to `std::ios_base::Init::Init()'
traits2.cpp:(.text+0x3b): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccI7CNCY.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
traits2.ccp文件包含上述带有emtpy main()函数的解决方案:
#include <iostream>
using namespace std;
// A default Traits class has no information
template<class T> struct Traits
{
};
// A convenient way to get the Traits of the type of a given value without
// …Run Code Online (Sandbox Code Playgroud) 我想在mac os上开发C++程序,我已经安装了Xcode和一堆框架.
但是我想编写没有Xcode IDE的代码,只需编写我自己的makefile并直接编译/链接gcc(随Xcode一起提供).
以opengl程序为例.我试着用命令编译它:
gcc -I/usr/include/-I/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/GLUT.framework/Headers/-I/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenGL.framework/Headers -L/usr/lib -L / usr/X11/lib/-L/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenGL.framework/Libraries/-lGL - lGLU -lGLUTt main.cpp
要么
gcc -I/usr/include/-L/usr/lib -framework OpenGL -framework GLUT -lm main.cpp
但他们最终导致链接错误
未定义的符号:
"std :: basic_ostream:: operator <<(long)",引用自:ccKBRSF9.o中的reshape(int,int).在ccKBRSF9.o"___gxx_personality_v0"中的display(),引用自:___ gxx_personality_v0 $ cc_BRKFF中的non_lazy_ptr(也许你的意思是:___ gxx_personality_v0 $ non_lazy_ptr) "的std ::的ios_base ::初始化::〜的init()",从引用:在ccKBRSF9.o ___tcf_0 "的std :: basic_string的,性病::分配器::运算符[](unsigned long类型)常量",引用from:std :: __ verify_grouping(char const*,unsigned long,std :: basic_string,std :: allocator> const&)在ccKBRSF9.o std :: __ verify_grouping(char const*,unsigned long,std :: basic_string,std :: ccKBRSF9.o中的allocator> const&)std :: __ verify_grouping(char const*,unsigned long,std ::在ccKBRSF9.o basic_string的,标准::分配器>常量和) "的std :: basic_ostream>&的std ::运算符<<(STD :: …
在 C++ 中你可以这样做
enum class Colors {black, blue, green, cyan, red, purple, yellow, white};
Colors mycolor;
mycolor = Colors::blue; // this is what I want to do
Run Code Online (Sandbox Code Playgroud)
在 中C,是否可以使用 来引用枚举EnumName::tag?
我已经将一个项目移植到 Arm Cortex M7 芯片上,并且第一次使用 makefile,我使用的是 gnu-gcc 编译器集合。
是否建议使用 gcc 驱动程序编译“c”代码,并使用 g++ 驱动程序编译“c++”(app)代码,然后链接。C 代码都是低级(头文件)寄存器访问地址等,并且不包含任何函数(尚)或附加源文件。
或者,如果需要的话可以修改头文件以使用 g++ 进行编译,我可以使用 g++ 编译器来编译所有内容吗?
我已设置它,以便 gcc 正在编译 c 文件,而 g++ 正在编译 c++ 并链接。
我正在尝试编译一个程序,以便它从不同的入口点启动。我正在使用 Ubuntu 20.04.5、GCC 和 G++ 9.4.0 运行 WSL1
我发现将标志添加-Wl,--entry=foo到编译器中会foo()作为入口函数进行链接。测试,这适用于 gcc,但不适用于 g++。
使用示例文件 src/main.c:
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("Entering %s:%s\n", __FILE__, __func__);
return 0;
}
int not_main()
{
printf("Entering %s:%s\n", __FILE__, __func__);
exit(0); // Necessary, otherwise it throws a segfault
}
Run Code Online (Sandbox Code Playgroud)
编译后的gcc -Wl,--entry=not_main -o entry.o src/main.c输出就是我想要的:Entering src/main.c:not_main。
但是,当使用 编译时g++ -Wl,--entry=not_main -o entry.o src/main.c,会出现以下警告:/usr/bin/ld: warning: cannot find entry symbol not_main; defaulting to 0000000000001080。
这默认为main()函数输出Entering …
指令:
#ifndef __cplusplus
#error C++ is required
#elif __cplusplus < 201402L
#error C++14 is required
#endif
Run Code Online (Sandbox Code Playgroud)
命令行: g++ -Wall -Wextra -std=c++14 -c -o header.o header.hpp
我的g ++版本: g++ (tdm-1) 4.9.2
C++14 is required即使我添加了错误也会生成-std=c++14,我不知道为什么.
请告诉我如何解决这个问题.