www.digitalmars.com         C & C++   DMDScript  

c++ - Why does DMC not link this correctly? What am I missing.

reply johnny masters jr <ZeroFive0005 hotmail.com> writes:
This small example program is not working. I have a feeling dmc does not link
header files to there cpp files automaticly. If someone could clue me into
what settings I need to make this test file work that would be sweet. There
are 3 files: main.cpp, mine.h, mine.cpp

CODE::

//  main.cpp
//---------------------------------
#include <cstdlib>
#include <iostream>
#include "mine.h"

using namespace std;

int main(int argc, char *argv[])
{
    int x = foo();
    cout << x << endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}


//mine.h
//------------------------
#ifndef _MINE_H
#define _MINE_H

int foo();

#endif


// mine.cpp
// ------------------
#include "mine.h"

int foo() {
    return 5;
}

I get this error when I try to compile with dmc main.cpp

C:\>dmc main.cpp
link main,,,user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

main.obj(main)
 Error 42: Symbol Undefined ?foo  YAHXZ (int cdecl foo(void ))

--- errorlevel 1
begin 644 error.txt

M+VYO:3L-"D]05$Q)3DL *%(I(&9O<B!7:6XS,B` 4F5L96%S92`W+C4P0C$-


M(%-Y;6)O;"!5;F1E9FEN960 /V9O;T!`64%(6%H *&EN="!C9&5C;"!F;V\H

`
end
begin 644 code.zip


M```(`*:+1C:N'Z<8IP```-T````(````;6%I;BYC<'!-S,L*PC`0!=!](/\P

M)279S[3UP2EA_I$9C6K>,THHB5YC!RB,\A<A%:07Q> :`QBA,1^+<)V< >R%


M"````&UI;F4N8W!P4\[,2\XI34E54,K-S$O5RU#BY>+ERLPK44C+S]?05*CF

M. ````8``````````0` `````````&UI;F4N:%!+`0(4"Q0````(`*:+1C:N
M'Z<8IP```-T````(``````````$`(````%0```!M86EN+F-P<%!+`0(4"Q0`


`
end
Feb 06 2007
parent Bertel Brander <bertel post4.tele.dk> writes:
johnny masters jr skrev:
 This small example program is not working. I have a feeling dmc does not link
 header files to there cpp files automaticly. 
Compilers does not normally include .cpp files automaically. I C++ (and C) there is not necessarily any connection between the name of some .h file and some .cpp file.
 I get this error when I try to compile with dmc main.cpp
 
 C:\>dmc main.cpp
 link main,,,user32+kernel32/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
 
 main.obj(main)
  Error 42: Symbol Undefined ?foo  YAHXZ (int cdecl foo(void ))
You need to list all the .cpp files on the commandline: dmc main.cpp mine.cpp -- Just another homepage: http://damb.dk But it's mine - Bertel
Feb 06 2007