Thread: .cpp linking problems

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    84

    .cpp linking problems

    each time when i define a header file in my main cpp and then use the classes i define in the header file in some different cpp file it gives me "undefine" error

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are you compiling on the command line or in an IDE?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    84
    Quote Originally Posted by matsp View Post
    Are you compiling on the command line or in an IDE?

    --
    Mats
    command line in Microsoft compiler

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Then I will guess that you are doing something like this:
    Code:
    cl -o myprog main.cpp
    where you should do:
    Code:
    cl -o myprog main.cpp class.cpp
    (Alternatives do exist).

    Edit: What I'm trying to say is that you need to tell the compiler which CPP files it should compile (and link). Just because you include a header file doesn't automatically mean that the source file with the implementation will be compiled/linked against.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    84
    Quote Originally Posted by matsp View Post
    Then I will guess that you are doing something like this:
    Code:
    cl -o myprog main.cpp
    where you should do:
    Code:
    cl -o myprog main.cpp class.cpp
    (Alternatives do exist).

    Edit: What I'm trying to say is that you need to tell the compiler which CPP files it should compile (and link). Just because you include a header file doesn't automatically mean that the source file with the implementation will be compiled/linked against.

    --
    Mats
    thanks for telling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking problems trying to compile QT application
    By Maragato in forum C++ Programming
    Replies: 1
    Last Post: 08-19-2005, 09:08 PM
  2. Grrr.... SDL Linking Problem
    By 7EVEN in forum Game Programming
    Replies: 5
    Last Post: 08-12-2005, 08:44 PM
  3. More linker problems
    By Ganoosh in forum C++ Programming
    Replies: 4
    Last Post: 07-12-2005, 10:27 PM
  4. Linking problems
    By Ganoosh in forum C++ Programming
    Replies: 4
    Last Post: 07-12-2005, 02:16 PM
  5. error LNK2001: unresolved external symbol
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 07-12-2002, 08:45 PM