Thread: Linkage error

  1. #1
    Registered User
    Join Date
    Jun 2021

    Linkage error


    I have used C in the past. but have gotten EXTREMELY rusty at it. I currently have four files in my directory (ex.c, ex.h, menu.c, and menu.h).

    menu.h is this:
    #ifndef MENU_H
    #define MENU_H
    #include <stdio.h>
    void print_header(void);
    int get_choice(void);
    menu.c is this:
    #include "menu.h"
    void print_header(void) {
        printf("--- Chapter 1 Examples ---\n");
    ex.h is this:
    #include <stdio.h>
    void ex_1(void);
    and ex.c is this:
    #include "ex.h"
    #include "menu.h"
    int main() {
        return 0;
    Currently, I am trying to run print_header in ex.c to make sure everything works but I am getting a linkage error.
    ex.c:(.text+0x9): undefined reference to `print_header' 
    collect2: error: ld returned 1 exit status
    Can someone refresh why this is happening and how to fix it? Thank you

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You need to compile everything
    gcc menu.c ex.c
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-14-2021, 07:16 PM
  2. Linkage error
    By kwzeet in forum C Programming
    Replies: 1
    Last Post: 01-30-2011, 06:49 AM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Get sense of internal linkage and external linkage
    By gandalf_bar in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2003, 05:57 AM
  5. help with static linkage error of member function
    By inandout in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2002, 11:20 AM

Tags for this Thread