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
M0SI</F1M8R!M86EN+F-P<`T*;&EN:R!M86EN+"PL=7-E<C,R*VME<FYE;#,R
M+VYO:3L-"D]05$Q)3DL *%(I(&9O<B!7:6XS,B` 4F5L96%S92`W+C4P0C$-
M"D-O<'ER:6=H="`H0RD 1&EG:71A;"!-87)S(#$Y.#D +2`R,#`Q("!!;&P 
M4FEG:'1S(%)E<V5R=F5D#0H-"FUA:6XN;V)J*&UA:6XI#0H 17)R;W( -#(Z
M(%-Y;6)O;"!5;F1E9FEN960 /V9O;T!`64%(6%H *&EN="!C9&5C;"!F;V\H
;=F]I9"`I*0T*#0HM+2T 97)R;W)L979E;"`Q
`
end
begin 644 code.zip
M4$L#!!0````(`%2+1C9XC0S/,````#H````&````;6EN92YH4\Y,RTM)35.(
M]_7T<XWWX.52!O(R\U(1`KQ<F7DE"FGY^1J:UB"><FI>2F8:+Q<`4$L#!!0`
M```(`*:+1C:N'Z<8IP```-T````(````;6%I;BYC<'!-S,L*PC`0!=!](/\P
MI)LJX ^T"E*Z<"?$ B`B,8UMH)E('J*(_VZ*#]Q<+F<NDVF40VP5E-*'=M"G
M)279S[3UP2EA_I$9C6K>,THHB5YC!RB,\A<A%:07Q> :`QBA,1^+<)V< >R%
M VGJU_UA0LD#`"A)`>/D! LX6YM/BK=)&P.49?(4"MOAX_[N S(YVZP:7K/O
MVJD0'4*]6V^/O*FJFO-T>5+R`E!+`P04````"`!KBT8V3H3(9#8````W````
M"````&UI;F4N8W!P4\[,2\XI34E54,K-S$O5RU#BY>+ERLPK44C+S]?05*CF
MY5(` J+4DM*B/`53:R";EZN6EPL`4$L!`A0+%````` `5(M&-GB-#,\P````
M. ````8``````````0` `````````&UI;F4N:%!+`0(4"Q0````(`*:+1C:N
M'Z<8IP```-T````(``````````$`(````%0```!M86EN+F-P<%!+`0(4"Q0`
M```(`&N+1C9.A,AD- ```#<````(``````````$`(````"$!``!M:6YE+F-P
7<%!+!08``````P`#`*````!]`0``````
`
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