Tag: 编译器错误

为什么LD_LIBRARY_PATH是BAD以及加载动态库的正确方法

所以,我有一个运行OpenBlas的程序,我想编译它。 链接过程如下所示: gcc -o prog prog.o -O3 -I/opt/OpenBLAS/include -L/opt/OpenBLAS/lib -lopenblas 到现在为止还挺好。 如果我删除-L选项,我在链接过程中出错 /usr/bin/ld: cannot find -lopenblas 使用-L所有链接都没有错误。 但是,当我尝试运行它时,我收到以下错误: ./prog: error while loading shared libraries: libopenblas.so.0: cannot open shared object file: No such file or directory 如果我将env变量LD_LIBRARY_PATH设置为/opt/OpenBlas/lib我可以运行该程序,但很多来源如http://xahlee.info/UnixResource_dir/_/ldpath.html认为这是一个不好的做法,我可以理解几乎所有的推理。 文章中提到的另一种方法(修改ld配置)也被认为是一种不好的做法。 最后,您可以在/usr/lib向库中添加符号链接。 最后两种方法的一个大问题是您需要sudo访问权限。 所以我的问题是如何在不使用LD_LIBRARY_PATH和sudo访问的情况下编译和运行链接到不在默认路径( /usr/lib )中的共享库的程序。 在文章中他们说你可以在二进制文件中“写”寻找共享库,但我不知道如何做( -L标志似乎没有这样做)。 我很感激,如果有人能解释这个问题,因为我一直在寻找各处,我很困惑(一些参考文献似乎表明标志’-L’应该这样做,但我不适合我)。 先感谢您。

取消引用proc_dir_entry指针导致Linux 3.11及更高版本上的编译错误

我试图按照这里给出的示例rootkit https://github.com/ivyl/rootkit 我修改了这个例子,以便我可以在linux 3.11版本上编译它。 我发现最新的linux版本停止支持几个API,例如create_proc_entry,readdir已经被迭代等替换。 在Linux版本是3.11.0-23我还观察到我的include目录不包含internal.h,以便有完整的proc_dir_entry定义。 在linux上的较低版本(<3.10),我们在proc_fs.h文件中定义了proc_dir_entry。 修改后的rootkit文件如下所示: #include #include #include #include #include #include //#include “fs/proc/internal.h” #define MIN(a,b) \ ({ typeof (a) _a = (a); \ typeof (b) _b = (b); \ _a < _b ? _a : _b; }) #define MAX_PIDS 50 MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Arkadiusz Hiler”); MODULE_AUTHOR(“Michal Winiarski”); //STATIC VARIABLES SECTION //we don’t want […]

包括来自另一个目录的头文件

我有一个主目录A有两个子目录B和C 目录B包含头文件structures.c : #ifndef __STRUCTURES_H #define __STRUCTURES_H typedef struct __stud_ent__ { char name[20]; int roll_num; }stud; #endif 目录C包含main.c代码: #include #include #include int main() { stud *value; value = malloc(sizeof(stud)); free (value); printf(“working \n”); return 0; } 但是我收到一个错误: main.c:3:24: error: structures.h: No such file or directory main.c: In function ‘main’: main.c:6: error: ‘stud’ undeclared (first use […]

是否可以使用python编译c代码?

我想构建一个python程序,它将.c文件的路径作为输入,然后编译它。 如果编译成功,程序将输出OK到屏幕,否则输出BAD。 我一直试图谷歌,但找不到任何东西。 我一直在尝试使用编译程序的参数在python中运行cmd,但它不起作用。 澄清 – 我已经在我的机器中有一个非常具体的编译器,我想运行它。 我不希望python充当编译器。 只需获取代码,在其上运行我的编译器,然后查看答案是什么。 它应该在使用python 2.4的Linux服务器上运行。 谢谢

字符串指针和c中的字符数组

我刚开始学习C并发现了一些关于字符串指针和字符串(char数组)的混淆。 任何人都可以帮我清醒一下吗? // source code char name[10] = “Apple”; char *name2 = “Orange”; printf(“the address of name: %p\n”, name); printf(“the address of the first letter of name: %p\n”, &(*name)); printf(“first letter of name using pointer way: %c\n”, *name); printf(“first letter of name using array way: %c\n”, name[0]); printf(“———————————————\n”); printf(“the address of name2: %p\n”, name2); printf(“the […]

无法编译使用ncurses的代码

我刚刚发现了ncurses并且刚开始学习它,但是我的教程中的示例不能在我的计算机上编译。 我必须手动安装ncurses,并输入“apt-get install libncurses5-dev libncursesw5-dev”。 我不得不这样做,因为在这样做之前我得到一个错误,说我不能“#include”。 安装它工作,但现在我得到此错误: touzen@comp:~/learning_ncurses$ g++ -o hello_world hello_world.cpp /tmp/ccubZbvK.o: In function `main’: hello_world.cpp:(.text+0xa): undefined reference to `initscr’ hello_world.cpp:(.text+0x16): undefined reference to `printw’ hello_world.cpp:(.text+0x1b): undefined reference to `refresh’ hello_world.cpp:(.text+0x20): undefined reference to `stdscr’ hello_world.cpp:(.text+0x28): undefined reference to `wgetch’ hello_world.cpp:(.text+0x2d): undefined reference to `endwin’ collect2: ld returned 1 exit status 我编译的代码如下所示: #include int […]

“collect2:error:ld返回1退出状态”是什么意思?

我看到错误collect2: error: ld returned 1 exit status经常collect2: error: ld returned 1 exit status 。 例如,我正在执行以下代码片段: void main() { char i; printf(“ENTER i”); scanf(“%c”,&i); clrscr(); switch(i) { default: printf(“\nHi..\n”); break; case 1: printf(“\n\na”); break; case 2: printf(“\nb\n”); break; case 3: printf(“\nc”); break; } } 我得到了这个: main.c:(.text+0x33): undefined reference to `clrscr’ collect2: error: ld returned 1 exit […]

冲突类型中的C错误

#define RAND_MAX 10 #include int main() { double x; x=randRange(-1.0,1.0); printf(“x value is %f::”,x); return 0; } double randRange(double min, double max) { return rand() * (max – min) / RAND_MAX + min; } 错误::以下片段是生成的错误 – $gcc main.c -o demo -lm -pthread -lgmp -lreadline 2>&1 main.c:11:8: error: conflicting types for ‘randRange’ double randRange(double min, double […]

错误C3861:’initNode’:找不到标识符

我收到编译错误: 错误C3861:’initNode’:找不到标识符“ 以下是代码: # include # include “stdafx.h” # include struct node{ node * next; int nodeValue; }; node*createList (int value) /*Creates a Linked-List*/ { node *dummy_node = (node*) malloc(sizeof (node)); dummy_node->next=NULL; dummy_node->nodeValue = value; return dummy_node; } void addFront (node *head, int num ) /*Adds node to the front of Linked-List*/ { node*newNode = […]

C错误:表达式必须具有常量值

我正在编写一些嵌入式代码,通过SPI与外部设备连接。 该设备有几个不同长度的寄存器,为了保持正确,我已经定义了以下结构 typedef struct { uint16_t Signed :1; // Register is signed or unsigned uint16_t CommLengthBytes :3; // The width of the register in bytes uint16_t Address :12; // Register address }ts_register; 然后,我在源代码中定义了每个寄存器,如下所示 static const ts_register SAGCYC = {0, 1, 0x000}; static const ts_register DISNOLOAD = {0, 1, 0x001}; static const ts_register LCYCMODE = {0, […]