Author Topic: Cannot compile wxwidget 'hello world' [SOLVED]  (Read 8712 times)

canassa

  • Guest
Cannot compile wxwidget 'hello world' [SOLVED]
« on: April 16, 2006, 08:15:44 pm »
I've been trying without sucess to compile the WxWidgets 'Hello Word' application with C::B. The problem occours at the linking part, this is the output:

Project   : Console application
Compiler  : GNU GCC Compiler (called directly)
Directory : C:\Projetos\teste03\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: main.cpp
main.cpp:76:2: warning: no newline at end of file
Linking console executable: C:\Projetos\teste03\console.exe
.objs\main.o(.text$_ZN12wxStringBaseC2EPKc[wxStringBase::wxStringBase(char const*)]+0x27):main.cpp: undefined reference to `_imp___ZN12wxStringBase8InitWithEPKcjj'
.objs\main.o(.rdata$_ZTV5MyApp[vtable for MyApp]+0x68):main.cpp: undefined reference to `wxApp::Initialize(int&, char**)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)
2 errors, 1 warnings

I guess I forgot to include a library, but I don't know which one.  :?

I don't if this helps, but this is my project file:

<?xml version="1.0"?>
<!DOCTYPE CodeBlocks_project_file>
<CodeBlocks_project_file>
   <FileVersion major="1" minor="1"/>
   <Project>
      <Option title="Console application"/>
      <Option makefile="Makefile"/>
      <Option makefile_is_custom="0"/>
      <Option compiler="0"/>
      <Build>
         <Target title="default">
            <Option output="C:\Projetos\teste03\console.exe"/>
            <Option working_dir="."/>
            <Option object_output=".objs"/>
            <Option deps_output=".deps"/>
            <Option type="1"/>
            <Option compiler="0"/>
            <Option projectResourceIncludeDirsRelation="1"/>
         </Target>
      </Build>
      <Compiler>
         <Add option="-DWXUSINGDLL"/>
         <Add directory="$(WXWIN)\contrib\include"/>
         <Add directory="$(WXWIN)\include"/>
         <Add directory="$(WXWIN)\lib\gcc_dll$(WX_CFG)\mswu"/>
      </Compiler>
      <ResourceCompiler>
         <Add directory="$(WXWIN)\contrib\include"/>
      </ResourceCompiler>
      <Linker>
         <Add library="wxmsw26u"/>
         <Add directory="$(WXWIN)\lib\gcc_dll"/>
      </Linker>
      <Unit filename="main.cpp">
         <Option compilerVar="CPP"/>
         <Option target="default"/>
      </Unit>
   </Project>
</CodeBlocks_project_file>


Thanks,
Canassa
« Last Edit: April 16, 2006, 10:46:22 pm by canassa »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Cannot compile wxwidget 'hello world'
« Reply #1 on: April 16, 2006, 09:05:22 pm »
You are linking against an unicode build.

Open Project options, go to compiler tab, and add wxUSE_UNICODE to the #defines field.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

canassa

  • Guest
Re: Cannot compile wxwidget 'hello world'
« Reply #2 on: April 16, 2006, 10:20:00 pm »
Thanks, it works now  :D

I still had some issues thought. Some conversion from wxString to char* problems, so I had to convert all strings to wxT("string"). The program also couldn't find the wxwidget dll. That's weird because I have it in my PATH... anyway, I just copied it to system32 and everything is working now :)

Thanks again,
Canassa

Offline RedAlert

  • Single posting newcomer
  • *
  • Posts: 6
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #3 on: March 21, 2007, 05:09:44 am »
I tried simple Helloworld template in C:B and had the same problem with canassa. After adding wxUSE_UNICODE in #define and rebuild, I got the following error:

---
main.cpp:49: error: call of overloaded `wxMenu(const char[1])' is ambiguous
C:/wxWidgets-2.8.0/include/wx/msw/menu.h:118: note: candidates are: wxMenu::wxMenu(const wxMenu&) <near match>
C:/wxWidgets-2.8.0/include/wx/msw/menu.h:55: note:                 wxMenu::wxMenu(long int) <near match>
C:/wxWidgets-2.8.0/include/wx/msw/menu.h:53: note:                 wxMenu::wxMenu(const wxString&, long int) <near match>
main.cpp:53: error: call of overloaded `wxMenu(const char[1])' is ambiguous
C:/wxWidgets-2.8.0/include/wx/msw/menu.h:118: note: candidates are: wxMenu::wxMenu(const wxMenu&) <near match>
C:/wxWidgets-2.8.0/include/wx/msw/menu.h:55: note:                 wxMenu::wxMenu(long int) <near match>
C:/wxWidgets-2.8.0/include/wx/msw/menu.h:53: note:                 wxMenu::wxMenu(const wxString&, long int) <near match>
Process terminated with status 1 (0 minutes, 8 seconds)
---

Is that C:B didn't realize wxMenu constructors? How do I solve out this problem?
Thank you for reading!

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #4 on: March 21, 2007, 05:48:58 am »
Why don't you use wxWidgets Project Wizard?

It's the most elegant way to start programming with wxWidgets. :)

Please try it, if you haven't used it earlier.
Be a part of the solution, not a part of the problem.

Offline RedAlert

  • Single posting newcomer
  • *
  • Posts: 6
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #5 on: March 21, 2007, 07:34:43 am »
Why don't you use wxWidgets Project Wizard?

It's the most elegant way to start programming with wxWidgets. :)

Please try it, if you haven't used it earlier.

Hi Biplab,

I started with File\New Project and choose wxWidgets Application. Did you mean that?

There's no problem if I use VC6. I compiled wxWidget-2.8.0 to use with both VC6 (non-unicode) & C:B (unicode)

BTW, sorry that's not helloworld program. It's a simple window with menu (you can test it using wxWidget template in C:B with defaults) ^^
« Last Edit: March 21, 2007, 07:41:37 am by RedAlert »

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #6 on: March 21, 2007, 09:14:09 am »
I started with File\New Project and choose wxWidgets Application. Did you mean that?

Yes I'm pointing to that only.

There's no problem if I use VC6. I compiled wxWidget-2.8.0 to use with both VC6 (non-unicode) & C:B (unicode)

I'm not very clear on your message. But C::B can handle all possible wxWidgets configurations excluding wxUniversal Build. So it doesn't matter if you are using Unicode/Non-unicode build. C::B has solutions for all. :)
Be a part of the solution, not a part of the problem.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4305
    • Code::Blocks IDE
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #7 on: March 21, 2007, 09:16:12 am »
Quote
Is that C:B didn't realize wxMenu constructors? How do I solve out this problem?

Learn to read the compiler's error messages. They are not printed just to decorate the build log...

Quote
There's no problem if I use VC6. I compiled wxWidget-2.8.0 to use with both VC6 (non-unicode) & C:B (unicode)

And if you 're gonna start comparing, don't compare apples to oranges. Your code wouldn't work with VC6 in unicode mode too, I guarantee you that. Just read the errors.
Be patient!
This bug will be fixed soon...

Offline RedAlert

  • Single posting newcomer
  • *
  • Posts: 6
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #8 on: March 21, 2007, 10:14:35 am »
There are more than 1 wxMenu constructor in main.h and the compiler doesn't know which one to choose. Am I right?

This is Unicode-related error so I think adding wxUSE_UNICODE must solve the problem. Do I miss anything?

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #9 on: March 21, 2007, 10:36:44 am »
Do I miss anything?

Yes! You are not understanding the role of C::B properly.

C::B is an IDE, which essentially helps you to communicate with compiler (which may be any) to compile a source. C::B doesn't bother what code you are putting in the source files and it sends the file in same condition to the compiler as you are supplying it.

There are more than 1 wxMenu constructor in main.h and the compiler doesn't know which one to choose. Am I right?

This is Unicode-related error so I think adding wxUSE_UNICODE must solve the problem.

Multiple wxMenu constructor is NOT a problem which is related to wxUSE_UNICODE (which essentially enables Unicode mode). It's your code which is the source of problem.

You can have multiple constructor of different wxMenu objects, but you can't construct the same object again and again in same piece of code. So it all depends on how you've crafted the code.

Sorry, C::B is not at fault in this case. C::B won't mess with or improve your buggy code.



BTW, looking at the error log, it seems that you are not wrapping char* with wxT() macro.

What I mean to say is if you have code similar to:
Code: [Select]
wxMenu* fileMenu = new wxMenu("My Menu");
Change it to:
Code: [Select]
wxMenu* fileMenu = new wxMenu(wxT("My Menu"));
« Last Edit: March 21, 2007, 10:42:27 am by Biplab »
Be a part of the solution, not a part of the problem.

Offline RedAlert

  • Single posting newcomer
  • *
  • Posts: 6
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #10 on: March 21, 2007, 11:49:01 am »
Thanks for your suggestions, Biplab. I tried & got the following error:

---
Switching to target: default
mingw32-g++.exe   -pipe -mthreads -Winvalid-pch -include "wx_pch.h" -DwxUSE_UNICODE -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DUSE_PCH -pipe -mthreads -Winvalid-pch -include "wx_pch.h" -DwxUSE_UNICODE -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DUSE_PCH    -IC:\wxWidgets-2.8.0\include -IC:\wxWidgets-2.8.0\lib\gcc_dll\mswu -IC:\wxWidgets-2.8.0\contrib\include -IC:\wxWidgets-2.8.0\include -IC:\wxWidgets-2.8.0\lib\gcc_dll\mswu -IC:\wxWidgets-2.8.0\contrib\include  -IC:\MinGW\include -c wx_pch.h -o wx_pch.h.gch

mingw32-g++.exe   -pipe -mthreads -Winvalid-pch -include "wx_pch.h" -DwxUSE_UNICODE -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DUSE_PCH -pipe -mthreads -Winvalid-pch -include "wx_pch.h" -DwxUSE_UNICODE -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DUSE_PCH    -IC:\wxWidgets-2.8.0\include -IC:\wxWidgets-2.8.0\lib\gcc_dll\mswu -IC:\wxWidgets-2.8.0\contrib\include -IC:\wxWidgets-2.8.0\include -IC:\wxWidgets-2.8.0\lib\gcc_dll\mswu -IC:\wxWidgets-2.8.0\contrib\include  -IC:\MinGW\include -c main.cpp -o .objs\main.o
cc1plus.exe: calling fdopen: Bad file descriptor
Process terminated with status 1 (0 minutes, 7 seconds)
0 errors, 0 warnings
---

This is not my source since I don't know anything about wxWidgets. It's automatically-generated source from C:B.
I understand what you mean. That's why I feel unusual when it causes error "..wxMenu...ambiguous".
But my explaination is so awkward, perhaps I have to study English writing before study programming ^^

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #11 on: March 21, 2007, 12:11:06 pm »
cc1plus.exe: calling fdopen: Bad file descriptor

I'm not sure about this error. But this could be the culprit.

This is not my source since I don't know anything about wxWidgets. It's automatically-generated source from C:B.

C::B generated source would compile properly with all versions of wx lib versions. It's well-tested code. Also you need not wrap it wxT() macro as it already does that for you.

Another point is when you are compiling a sample application, you can turn off PCH support. It's necessary if you're compiling a large project. Otherwise overhead will eat up advantage.

But my explaination is so awkward, perhaps I have to study English writing before study programming ^^

Don't worry, Not all of us are native English speakers. ;)
Be a part of the solution, not a part of the problem.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4305
    • Code::Blocks IDE
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #12 on: March 21, 2007, 01:43:01 pm »
cc1plus.exe: calling fdopen: Bad file descriptor

You have #included the PCH header in a header file.
PCH should only be #included in source files (e.g. *.cpp).
Be patient!
This bug will be fixed soon...

Offline RedAlert

  • Single posting newcomer
  • *
  • Posts: 6
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #13 on: March 22, 2007, 03:29:32 am »
Finally I got it run! After recompile wxWidget, I have to modify the source code, which automatically generated by C::B
wxMenu* fileMenu = new wxMenu("");------>wxMenu* fileMenu = new wxMenu;
Compile & run are alright now.

I forgot to tell that I am using C::B 1.0 rc2 with wxWidget2-8.0 and the template code is automatically generated. I think that template code must run without any modification.

@Biplab: I eliminated USE_PCH option but there still has a file wx_pch.h.gch in output directory.
@mandrav: Can you explain a bit more since I don't have knowledge of wxWidgets before? What header file do you mention? There is only one wx_pch.h generated.

Thanks for all your help!

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Cannot compile wxwidget 'hello world' [SOLVED]
« Reply #14 on: March 22, 2007, 06:19:00 am »
I forgot to tell that I am using C::B 1.0 rc2 with wxWidget2-8.0 and the template code is automatically generated. I think that template code must run without any modification.

This is the root cause to your problem. Code::Blocks RC2 is a very old release and a huge number of changes have been made to Code::Blocks so far. wxWidgets wizard has also got an overhaul. So download a latest nightly from the following forum.

Quote
http://forums.codeblocks.org/index.php/board,20.0.html

Don't forget to Uninstall the RC2.

@Biplab: I eliminated USE_PCH option but there still has a file wx_pch.h.gch in output directory.

I think your project still has PCH support. You can safely delete that file. :)
Be a part of the solution, not a part of the problem.