Topic: Problem with Hello World using C++

Hi,

I just started using a trial version of Simply Fortran and tried to create a simple hello world program using c++. I have created a project and saved the file with the .cpp extension. The code is:

"#include <iostream>

int main(int argc, char **argv) {
  std::cout << "Hello world!\n";
  return 0;
}"

I get a bunch of error messages when compiling though:

Open Watcom Make Version 1.9 (Built on May 17 2012)
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
    "C:\Program Files (x86)\Simply Fortran\mingw-w64\bin\gcc.exe" -c -o "build\main.o" -g -m32   ".\main.cpp"
    "C:\Program Files (x86)\Simply Fortran\mingw-w64\bin\gfortran.exe" -o "hello.exe" -static -m32 "build\main.o" -LC:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/ -LC:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc_eh.a when searching for -lgcc_eh
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc.a when searching for -lgcc
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc_eh.a when searching for -lgcc_eh
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc.a when searching for -lgcc
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc_eh.a when searching for -lgcc_eh
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc.a when searching for -lgcc
build\main.o: In function `swscanf':
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/wchar.h:459: undefined reference to `__gxx_personality_sj0'
build\main.o: In function `wscanf':
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/wchar.h:470: undefined reference to `__gxx_personality_sj0'
build\main.o: In function `fwscanf':
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/wchar.h:481: undefined reference to `__gxx_personality_sj0'
build\main.o: In function `fwprintf':
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/wchar.h:517: undefined reference to `__gxx_personality_sj0'
build\main.o: In function `wprintf':
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/wchar.h:528: undefined reference to `__gxx_personality_sj0'
build\main.o:c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/wchar.h:539: more undefined references to `__gxx_personality_sj0' follow
build\main.o: In function `_tcf_0':
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/c++/4.7.2/iostream:75: undefined reference to `std::ios_base::Init::~Init()'
build\main.o: In function `_static_initialization_and_destruction_0':
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include/c++/4.7.2/iostream:75: undefined reference to `std::ios_base::Init::Init()'
collect2.exe: error: ld returned 1 exit status
Error(E42): Last command making (hello.exe) returned a bad status
Error(E02): Make execution terminated

* Complete *

It seems like it is "skipping incompatible" for -lgcc. Does anyone know how I should fix that?

Regards
Ronny

Re: Problem with Hello World using C++

Ronny,

You'll just need to add the following to the Linker Flags in the Project Options dialog (accessible via the Options... item in the Project menu):

-lstdc++

Your code should compile fine with that addition.

The flag is necessary because Simply Fortran is using the gfortran command for linking rather than g++, which would implicitly link the standard C++ library.

Jeff Armstrong
Approximatrix, LLC

Re: Problem with Hello World using C++

Thank you for the fast answer Jeff, it worked like a charm!

I am still getting the "skipping incompatible" things though. Is there anything I can do about that, or does that not affect me at all?
This is what the output looks like when I build:

Open Watcom Make Version 1.9 (Built on May 17 2012)
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
    "C:\Program Files (x86)\Simply Fortran\mingw-w64\bin\gcc.exe" -c -o "build\main.o" -g -m32   ".\main.cpp"
    "C:\Program Files (x86)\Simply Fortran\mingw-w64\bin\gfortran.exe" -o "hello.exe" -static -m32 "build\main.o" -LC:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/ -LC:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2 -lstdc++
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc_eh.a when searching for -lgcc_eh
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc.a when searching for -lgcc
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc_eh.a when searching for -lgcc_eh
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc.a when searching for -lgcc
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc_eh.a when searching for -lgcc_eh
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/gcc/X86_64~1/475CEE~1.2\libgcc.a when searching for -lgcc

* Complete *

//Ronny

Re: Problem with Hello World using C++

Ronny,

I'm wondering about the library paths you have set up.  In project options, when you open Search Directories, try removing anything but the default directories.  It appears that the compiler is searching the 64-bit libraries, but you're building a 32-bit executable.  During the linking phase, the compiler is encountering libraries that appear to be named properly, but are actually for the 64-bit targets.  Hence, you're seeing the compiler ignoring these 64-bit libraries.

When I compile and run your program, I'm not seeing any such warnings.  I think if you just remove those library search paths, you should be okay.

Jeff Armstrong
Approximatrix, LLC

Re: Problem with Hello World using C++

Thanks again Jeff! I removed the extra ones without looking what I had put there originally, so I can't tell you what was there before. But now everything is working as it should.

Again, thank you so much!
//Ronny

Re: Problem with Hello World using C++

Great to hear, Ronny!

Jeff Armstrong
Approximatrix, LLC