playing with namespaces...

G

Gernot Frisch

Hi,

I have a set of functions that I enclousured into a namespace due to
some conflicts.

// XYZ.h
//------
namespace CC
{
void foo();
double dfoo=0;
}

// XYZ.cpp
//--------
namespace CC
{
void foo() {dfoo=1;}
}

using namepsace CC;
int APIENTRY WinMAIN(..)
{
dfoo = 2;
foo();
}

without the namespace everything was OK, but now my GCC says:

...\lib/libc.a(winmain.o)(.text+0x14): undefined reference to `main'

Can you help?


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
S

Sharad Kala

Gernot Frisch said:
Yes, sure - but that wasn't it. I just typed it here quickly for demo
purposes...

Then your problem lies somewhere else. This compiles fine for me on g++
3.3.1.

namespace CC
{
void foo();
double dfoo=0;
}

namespace CC
{
void foo() {dfoo=1;}
}

using namespace CC;
int main()
{
dfoo = 2;
foo();
}
 
K

Karl Heinz Buchegger

Gernot said:
Hi,

I have a set of functions that I enclousured into a namespace due to
some conflicts.

// XYZ.h
//------
namespace CC
{
void foo();
double dfoo=0;
}

// XYZ.cpp
//--------
namespace CC
{
void foo() {dfoo=1;}
}

using namepsace CC;
int APIENTRY WinMAIN(..)
{
dfoo = 2;
foo();
}

without the namespace everything was OK, but now my GCC says:

..\lib/libc.a(winmain.o)(.text+0x14): undefined reference to `main'

the linker is searching for a function

int main()
{
}

You have a function

int APIENTRY WinMAIN(..)
{
}

Does this ring a bell?
 
G

Gernot Frisch

Karl Heinz Buchegger said:
`main'

the linker is searching for a function

int main()
{
}

You have a function

int APIENTRY WinMAIN(..)
{
}

Does this ring a bell?

Just another typo. As I mentioned: Without the "namespace CC" thingy,
everything works correctly...

Really strange, huh?
-Gernot
 
S

Sharad Kala

Just another typo. As I mentioned: Without the "namespace CC" thingy,
everything works correctly...

How about posting the full program, if possible, without any typos i.e.
copy-and-paste ;-)
 
R

Rolf Magnus

Gernot said:
Just another typo. As I mentioned: Without the "namespace CC" thingy,
everything works correctly...

Really strange, huh?

Could you please provide code that you tested so it doesn't contain any
of those typos. It's hard to look for errors in your original code if
you present instead code that has lots of other errors.
So make a short version of your program that you actually compiled and
that produced the specified error.
 
G

Gernot Frisch

// a.h
#include "windows.h"
namespace __GLBASIC__
{
void MainGame(void);
}



// a.cpp
#include "gpc_temp.h"
namespace __GLBASIC__
{

void __MainGameSub_(void)
{ }

}

using namespace __GLBASIC__;

// Entry Point
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
__MainGameSub_();
return 0;
}

Gives this error.
 
K

Karl Heinz Buchegger

Gernot said:
// a.h
#include "windows.h"
namespace __GLBASIC__
{
void MainGame(void);
}

// a.cpp
#include "gpc_temp.h"
namespace __GLBASIC__
{

void __MainGameSub_(void)
{ }

}

using namespace __GLBASIC__;

// Entry Point
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
__MainGameSub_();
return 0;
}

Gives this error.

And one more time. The linker searches for an entry point
of

int main()

in your program.

WinMain() is something that only a Windows compiler and Windows
linker understands. Microsoft put some standard code into
main(), which eg. gets the values for the Instance handles etc.
and then calls WinMain(). So in this environment, there is a main()
function, it comes from a library provided by Microsoft which does
initial startup initialization and then calls WinMain() as a replacement
for a user written main().

If you port such a thing to a differnt compiler on a different system,
it is *you* who has to provide a main() function as you then have
left the world of Microsoft.
 
G

Gernot Frisch

WinMain() is something that only a Windows compiler and Windows
linker understands. Microsoft put some standard code into
main(), which eg. gets the values for the Instance handles etc.
and then calls WinMain(). So in this environment, there is a main()
function, it comes from a library provided by Microsoft which does
initial startup initialization and then calls WinMain() as a replacement
for a user written main().

If you port such a thing to a differnt compiler on a different system,
it is *you* who has to provide a main() function as you then have
left the world of Microsoft.

Sure, I know that - but ... wait ... Oh no!!! Now it gives me the
error even _if_ I exclude the namespace thingy... But it compiled
before!?
What .a am I missing? It used to work until yesturday... And all I did
was introducing namespaces.
-Gernot
 
G

Gernot Frisch

It was a wrong definition of TCHAR for the WinMain function - sorry I
have bothered you, thank you for your help.
-Gernot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,486
Latest member
websterztechnologies01

Latest Threads

Top