www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



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

↑ ↓ ← 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
Feb 06 2007
↑ ↓ → 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