我正在尝试从其他c程序编译一个简单的c文件.我通过一个简短的shell脚本调用gcc(我知道我可以直接执行此操作,但这是一个测试).这是我的代码:
我的主程序(小块):
char strCommand[100];
sprintf(strCommand, "./compile.sh %s %u", fileName, nr);
FILE *pipe = popen(strCommand, "r");
if (pipe == NULL) {
perror("Unable to open compile script");
exit(-1);
}
char path[LINE_BUFSIZE];
while (fgets(path, LINE_BUFSIZE, pipe) != NULL)
printf("%s", path);
pclose(pipe);
Run Code Online (Sandbox Code Playgroud)
我的shell脚本:
#!/bin/bash
gcc $1 -o foo-$2
Run Code Online (Sandbox Code Playgroud)
和应该编译的文件;-):
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("Hello world");
}
Run Code Online (Sandbox Code Playgroud)
当我直接从终端调用bash脚本时,一切正常.但是,当从c程序调用我的脚本时,会发生以下错误:
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol …Run Code Online (Sandbox Code Playgroud) 我正在尝试重载&enum类的运算符,但是我得到了这个编译器错误:错误:'operator&='不匹配(操作数类型是'int'和'Numbers').有关于此的任何想法?
#include <iostream>
using namespace std;
enum class Numbers : int
{
zero = 0,
one = 0x01,
two = 0x02
};
inline int operator &(int a, Numbers b)
{
return ((a) & static_cast<int>(b));
}
int main() {
int a=1;
a&=Numbers::one;
cout << a ;
return 0;
}
Run Code Online (Sandbox Code Playgroud)