[英]Error compiling modular code in VSC using gcc
我在編譯以下程序時遇到問題:
// hauptteil.c (main part)
#include "nebenfkt.h"
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int x =10;
int ergebnis=0;
ergebnis =ver(x);
printf("Doubled number: %d", ergebnis);
return 0;
}
//nebenfkt.h
int ver(int x);
#include "nebenfkt.h"
#include <stdio.h>
#include <stdlib.h>
int ver(int x)
{
int rueck;
rueck= x*2;
return rueck;
}
VSC 給了我反饋“* undefined reference to `ver' collect2.exe: error: ld returned 1 exit status*”
出現問題是因為我只使用了命令“gcc hauptteil.c -o 函數”而不是“gcc hauptteil.c nebenfkt.Z4A8A08F09D37B737B8F334 函數”
我不了解您使用的“nebenfkt.h”庫,我的 VSC 也無法識別它。 刪除它后,代碼工作得很好。
這就是我將您的代碼粘貼到編譯器上的方式:
#include <stdio.h>
#include <stdlib.h>
int ver(int x)
{
int rueck;
rueck= x*2;
return rueck;
}
int main (void)
{
int x =10;
int ergebnis=0;
ergebnis =ver(x);
printf("Doubled number: %d", ergebnis);
return 0;
}
如果您仍然遇到同樣的問題,請檢查您的文件名中沒有特殊情況,並且您添加了正確的擴展名(如.c)
Eugene Sh 發現了我的錯誤。
我的錯誤是我只使用了命令“gcc hauptteil.c -o function”而不是“gcc hauptteil.c nebenfkt.Z4A8A08F09D37B73B8F334 function”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.