Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 531821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:20:27+00:00 2026-05-13T09:20:27+00:00

I got the following error message while compiling, but I’m sure I have the

  • 0

I got the following error message while compiling, but I’m sure I have the variables declared in an external Project2.c file. Could someone give me a hint what I did wrong? Thank you

1>main.obj : error LNK2001: unresolved external symbol _num_days
1>main.obj : error LNK2019: unresolved external symbol _countDays referenced in function _testIt
1>main.obj : error LNK2001: unresolved external symbol _what_birthday
1>main.obj : error LNK2001: unresolved external symbol _birth_day
1>main.obj : error LNK2001: unresolved external symbol _birth_month
1>main.obj : error LNK2001: unresolved external symbol _birth_year

Source code:

#include <stdio.h>

/* the following five variables are defined inside project2.c */
extern int birth_year; 
extern int birth_month;
extern int birth_day;
extern int what_birthday;
extern int num_days;

void countDays(void); // a declaration of your function

int num_tests_passed = 0;

void testIt(int test_num, 
        int year, int month, int day, int bday, int expected) {
    birth_year = year;
    birth_month = month;
    birth_day = day;
    what_birthday = bday;
    countDays();
    printf("your answer to test %d was %d, should have been %d\n", 
        test_num, num_days, expected);

    /* check the correctness and quality of their solution */
    if (num_days == expected) {
        if ((birth_year == year) && (birth_month == month) 
                && (birth_day == day)) {
            num_tests_passed += 1;
        } else {
            printf("you got the answer correct,"
                "but you don't follow instructions very well\n");
        }
    } else {
        printf("oops.\n");
    }
}


int main(void) {
    /* test #1: Born Feb 4, 1964 and about to turn 41 */
    testIt(1, 1964, 2, 4, 41, 41 * 365 + 11); // feb 29ths in '64, 68, 72,
                            // 76, 80, 84, 88, 92, 96, 00, and 04 (11 days)

    /* test #2: Born Jan 22, 1998 and about to turn 2 */
    testIt(2, 1998, 1, 22, 2, 2 * 365); // no leap days

    /* test #3: Born March 22, 1998 and about to turn 2 */
    testIt(3, 1998, 3, 22, 2, 2 * 365 + 1); // feb 29, 2000

    /* test #4: Born March 22, 1898 and about to turn 2 */
    testIt(4, 1898, 3, 22, 2, 2 * 365); // no leap days

    /* test #5: Born Jan 22, 1996 and about to turn 4 */
    testIt(5, 1996, 1, 22, 4, 4 * 365 + 1); // feb 29, 1996

    /* test #6: Born March 22, 1996 and about to turn 4 */
    testIt(6, 1996, 3, 22, 4, 4 * 365 + 1); // feb 29, 2000

    /* test #7: Born March 22, 1796 and about to turn 4 */
    testIt(7, 1796, 3, 22, 4, 365 * 4); // no leap days

    /* test #8: Born Jan 1, 1800 and about to turn 101 */
    testIt(8, 1800, 1, 1, 101, 101 * 365 + 24); // There are 26 years divisible by 4
                    // between 1800 and 1901, all of these except 1800 and 1900 are leap years
                    // so there are 24 leap days
    /* test #9: born Jan 1, 1900 and about to turn 100 */
    testIt(9, 1900, 1, 1, 100, 100 * 365 + 24); // 26 years divisible by 4
                    // 1900 was not a leap year, and the 100th brithday comes
                    // before Feb 29, 2000, so only 24 leap days.


    if (num_tests_passed == 9) {
        printf("all tests passed successfully.  Well done!\n");
    } else {
        printf("you only passed %d of the 9 tests.  Looks like you've got some work to do\n",
            num_tests_passed);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:20:28+00:00Added an answer on May 13, 2026 at 9:20 am

    In your project2.c, make sure you have those variables defined, and that the file is indeed part of your solution. If the source file is omitted than understandably, the linker will complain as it could not find the definitions.

    Normally, the best practice is to put those variables into a header file and defined.

    For a simplistic example, call this header file project2.h:

    /* project2.h */
    extern int birth_year; 
    extern int birth_month;
    extern int birth_day;
    extern int what_birthday;
    extern int num_days;
    

    Here, to follow on the example here’s your code with the extern variables omitted and in place an #include instead. Let’s also give this file an name called myproject1.c

    #include <stdio.h>
    #include "project2.h"
    
    void countDays(void); // a declaration of your function
    
    int num_tests_passed = 0;
    
    void testIt(int test_num, 
            int year, int month, int day, int bday, int expected) {
        birth_year = year;
        birth_month = month;
        birth_day = day;
        what_birthday = bday;
        countDays();
        printf("your answer to test %d was %d, should have been %d\n", 
            test_num, num_days, expected);
    
        /* check the correctness and quality of their solution */
        if (num_days == expected) {
            if ((birth_year == year) && (birth_month == month) 
                            && (birth_day == day)) {
                    num_tests_passed += 1;
            } else {
                    printf("you got the answer correct,"
                            "but you don't follow instructions very well\n");
            }
        } else {
            printf("oops.\n");
        }
    }
    
    
    int main(void) {
        /* test #1: Born Feb 4, 1964 and about to turn 41 */
        testIt(1, 1964, 2, 4, 41, 41 * 365 + 11); // feb 29ths in '64, 68, 72,
                                                    // 76, 80, 84, 88, 92, 96, 00, and 04 (11 days)
    
        /* test #2: Born Jan 22, 1998 and about to turn 2 */
        testIt(2, 1998, 1, 22, 2, 2 * 365); // no leap days
    
        /* test #3: Born March 22, 1998 and about to turn 2 */
        testIt(3, 1998, 3, 22, 2, 2 * 365 + 1); // feb 29, 2000
    
        /* test #4: Born March 22, 1898 and about to turn 2 */
        testIt(4, 1898, 3, 22, 2, 2 * 365); // no leap days
    
        /* test #5: Born Jan 22, 1996 and about to turn 4 */
        testIt(5, 1996, 1, 22, 4, 4 * 365 + 1); // feb 29, 1996
    
        /* test #6: Born March 22, 1996 and about to turn 4 */
        testIt(6, 1996, 3, 22, 4, 4 * 365 + 1); // feb 29, 2000
    
        /* test #7: Born March 22, 1796 and about to turn 4 */
        testIt(7, 1796, 3, 22, 4, 365 * 4); // no leap days
    
        /* test #8: Born Jan 1, 1800 and about to turn 101 */
        testIt(8, 1800, 1, 1, 101, 101 * 365 + 24); // There are 26 years divisible by 4
                                    // between 1800 and 1901, all of these except 1800 and 1900 are leap years
                                    // so there are 24 leap days
        /* test #9: born Jan 1, 1900 and about to turn 100 */
        testIt(9, 1900, 1, 1, 100, 100 * 365 + 24); // 26 years divisible by 4
                                    // 1900 was not a leap year, and the 100th brithday comes
                                    // before Feb 29, 2000, so only 24 leap days.
    
    
        if (num_tests_passed == 9) {
            printf("all tests passed successfully.  Well done!\n");
        } else {
            printf("you only passed %d of the 9 tests.  Looks like you've got some work to do\n",
                    num_tests_passed);
        }
    }
    

    Then in project2.c you would do this

    /* ... */
    int birth_year; 
    int birth_month;
    int birth_day;
    int what_birthday;
    int num_days;
    
    /* functions... */
    

    And that your solution composes of

    • project2.h
    • myproject1.c
    • project2.c

    Then the project should compile without any linker errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 312k
  • Answers 312k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't think you can do anything like that in… May 13, 2026 at 10:31 pm
  • Editorial Team
    Editorial Team added an answer If you look at the implementation of ProfileBase you will… May 13, 2026 at 10:31 pm
  • Editorial Team
    Editorial Team added an answer document.all is a proprietary Microsoft extension to the W3C standard.… May 13, 2026 at 10:31 pm

Related Questions

Compiling on Fedora 10. I am using qt for the first time. I started
Running OS X Leopard an MacBook Pro from Jan. 2008. I used to run
I have a .NET Windows serivce protected with {smartassembly} which works fine, except that
I've got problems installating the VMWARE ESXi Server. The Installation finishes without any error
This one has me scratching my head, so I'm hoping a second pair of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.