By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

playing with namespaces...

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a

"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2n************@uni-berlin.de...
Hi,
using namepsace CC;


See the spelling of namespace.

-Sharad

Jul 22 '05 #2

P: n/a
> > using namepsace CC;

See the spelling of namespace.

Yes, sure - but that wasn't it. I just typed it here quickly for demo
purposes...
Jul 22 '05 #3

P: n/a

"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2n************@uni-berlin.de...
using namepsace CC;


See the spelling of namespace.

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();
}
Jul 22 '05 #4

P: n/a
Gernot Frisch wrote:

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?

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #5

P: n/a

"Karl Heinz Buchegger" <kb******@gascad.at> schrieb im Newsbeitrag
news:41***************@gascad.at...
Gernot Frisch wrote:

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?


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

Really strange, huh?
-Gernot
Jul 22 '05 #6

P: n/a
> 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 ;-)
Jul 22 '05 #7

P: n/a
Gernot Frisch wrote:

"Karl Heinz Buchegger" <kb******@gascad.at> schrieb im Newsbeitrag
news:41***************@gascad.at...
Gernot Frisch wrote:
>
> 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?


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.

Jul 22 '05 #8

P: n/a
// 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.
Jul 22 '05 #9

P: n/a
Gernot Frisch wrote:

// 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.
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #10

P: n/a
> 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
Jul 22 '05 #11

P: n/a
It was a wrong definition of TCHAR for the WinMain function - sorry I
have bothered you, thank you for your help.
-Gernot
Jul 22 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.