簡體   English   中英

使用 CodeBlocks 對“函數”的未定義引用

[英]Undefined reference to 'function' using CodeBlocks

我用一個簡單的項目開始學習 CodeBlocks 時出現以下錯誤。

E:\CodeBlocks\Projects\Triplet-CLEON-Benjamin\main.c|5|undefined reference to `initTriplet'|
C:\msys64\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\12.1.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: E:\CodeBlocks\Projects\Triplet-CLEON-Benjamin\main.c|7|undefined reference to `AfficheTriplet'|

我的項目中只有 3 個文件,分別是:

主程序

#include "triplet.h"

int main()
{
    triplet myTriplet = initTriplet(5,8,7);

    AfficheTriplet(myTriplet);

    return 0;
}

三胞胎.c

#include "triplet.h"
#include <stdio.h>

void AfficheTriplet(triplet myTriplet)
{
    printf("Triplet: \n\t Premier %d\n\t Second %d\n\t Troisieme %d", myTriplet.p, myTriplet.d, myTriplet.t);
}

triplet initTriplet(int a, int b, int c)
{
    triplet myTriplet = {a,b,c};

    return myTriplet;
}

三元組

#ifndef TRIPLET_H_INCLUDED
#define TRIPLET_H_INCLUDED

typedef struct triplet triplet;
struct triplet
{
    int p;
    int d;
    int t;
};

triplet triTripletV1(triplet myTriplet);
void    triTripletV2(triplet myTriplet);

void AfficheTriplet(triplet myTriplet);
triplet initTriplet(int a, int b, int c);

#endif // TRIPLET_H_INCLUDED

在我的主文件中,如果我包含三元組,則如果我包含triplet.h,則運行其他工作,我有以前的錯誤。

此外,我的項目構建為

  • 項目名稱
    • 來源
      • 主程序
      • 三胞胎.c
    • 標頭
      • 三元組

請問有什么幫助嗎?

我在 CodeBlocks 中編譯你的應用程序沒有任何問題,所以問題可能是頭文件和源文件不是你項目的一部分。 如果您已經創建了一個項目,那么您可以嘗試以下操作:

  1. 打開您的項目 (*.cbp)
  2. 單擊名為“項目”的選項卡
  3. 點擊“添加文件...”
  4. 選擇所有源文件和頭文件(triplet.c 和triplet.h)
  5. 點擊“打開”
  6. 構建你的項目

我找到了答案,這只是一個設置錯誤......

在我的文件選項中,我必須擁有:

  • main.c => 編譯文件和鏈接文件
  • Triplet.c => 編譯文件和鏈接文件
  • Triplet.h => 沒有人

如果我右鍵單擊 -> 屬性 -> 在每個文件上構建一個文件,我必須確保選中了“調試”復選框。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM