Author Topic: Possible Bug: File not Recognized [SOLVED]  (Read 10031 times)

cprgmswr2

  • Guest
Possible Bug: File not Recognized [SOLVED]
« on: April 03, 2007, 07:17:40 pm »
I am getting a strange error with code blocks:

The build output:
Code
Compiling: CString.CPP
Precompiling header: CString.h
Compiling: Pointer.CPP
Precompiling header: Pointer.h
Compiling: SClass.cpp
Precompiling header: SClass.h
Compiling: SFunction.cpp
Precompiling header: SFunction.h
Compiling: SProcedure.cpp
Precompiling header: SProcedure.h
Compiling: ShortestPath.cpp
Precompiling header: ShortestPath.h
Compiling: ShortestPath.rc
Linking executable: ShortestPath.exe
CString.h.gch\default_CString_h_gch: file not recognized: File format not recognized
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 44 seconds)
0 errors, 0 warnings

I then proceeded to compile the exact same files through a batch file.

The batch file:
Code
c:\mingw\bin\windres -o resfile.o ShortestPath.rc 2> Error.txt
c:\mingw\bin\g++ -s -o shortestPath CString.CPP Pointer.CPP SClass.CPP SFunction.CPP ShortestPath.CPP SProcedure.CPP resfile.o C:\mingw\lib\libcomctl32.a -mwindows 2>> Error.txt

Produced no errors and made an executable with the batch file.

Is there any suggestion on how to solve this issue, so I can get code blocks to create an executable.?

Forgot to mention I am in windows using the March 31st, 2007 nightly build
« Last Edit: April 03, 2007, 07:56:51 pm by cprgmswr2 »

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Possible Bug: File not Recognized
« Reply #1 on: April 03, 2007, 07:27:57 pm »
This is not a C::B bug, rather it's related to linker.

Also the comparison is not perfect. In the second example you didn't create PCH file.

Delete the file CString.h.gch\default_CString_h_gch and recompile your project. :)

Regards,

Biplab
Be a part of the solution, not a part of the problem.

cprgmswr2

  • Guest
Re: Possible Bug: File not Recognized
« Reply #2 on: April 03, 2007, 07:32:21 pm »
I have deleted all .gch files over and over. I have rebuild the project numerous times yet it continues to fail at recognizing the file.

Is there a way to prevent it from making those files?

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Possible Bug: File not Recognized
« Reply #3 on: April 03, 2007, 07:39:32 pm »
Right click on CString.h file in Project Manager. Click on Properties menu option. Go to Build tab and uncheck Compile file option.

If you've set any pre-processor directive for PCH support you have to remove them, too. :)
Be a part of the solution, not a part of the problem.

cprgmswr2

  • Guest
Re: Possible Bug: File not Recognized
« Reply #4 on: April 03, 2007, 07:42:59 pm »
After unchecking compile file for the cstring.cpp file, I get this error

Code
-------------- Build: default in Win32 Application ---------------
Linking executable: ShortestPath.exe
mingw32-g++.exe: .objs\CString.o: No such file or directory
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings

--- Modified ---

I relized I had done the wrong file it was suppose to be the .h file, but I get this error instead

Code
Linking executable: ShortestPath.exe
mingw32-g++.exe: CString.h.gch\default_CString_h_gch: No such file or directory
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
« Last Edit: April 03, 2007, 07:44:50 pm by cprgmswr2 »

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Possible Bug: File not Recognized
« Reply #5 on: April 03, 2007, 07:43:51 pm »
Somehow, your header files all have the options to compile and link them enabled. Disable this by right-clicking each .h file in Code::Blocks, selecting Properties, selecting the Build tab, and unchecking the "Compile file" and "Link file" boxes.

I'll try to explain the reason for the error Code::Blocks is giving you: Currently, C::B interprets a header file with the "Compile file" option enabled as a header that should be precompiled, for faster inclusion in multiple source files. This is why you see all of the "Precompiling header: ..." lines. Then, since the files also have the "Link file" option enabled, the resulting precompiled-header file is passed to the linker, which is not designed to use it; thus the final "File format not recognized" error.

Appropriate use of precompiled headers is a good thing for large projects that include a certain set of headers in many different source files. Suffice it to say that the use of precompiled headers is not necessary, and your project is not set up for it, so I won't elaborate any further.

I also note that your batch file uses the simpler (traditional beginner's) method of compiling straight to an executable from the source code, without an intermediate object-code step. There is nothing wrong with this, but since it obscures the multi-phase (preprocess, compile, assemble, link) nature of modern C/C++ compilers you may not be familiar with what "linking object files" means. Code::Blocks (and other IDEs) split the compilation process into "compile" (which includes preprocessing and assembling) and "link" phases in order to avoid recompiling source files that have not changed since the last build. This is the standard method for building large programs, and works just as well for small ones.

Cheers,
John E. / TDM

Addendum: There have been several further posts during the time I was composing mine. CString.cpp needs the "Compile file" and "Link file" options checked, as do your other .cpp files. CString.h (and your other headers) need them unchecked.
« Last Edit: April 03, 2007, 07:49:20 pm by TDragon »
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Possible Bug: File not Recognized
« Reply #6 on: April 03, 2007, 07:51:23 pm »
Thanks John E. for the nice explanatory reply. I've to keep my reply short as I'm busy in another work. :)
Be a part of the solution, not a part of the problem.

cprgmswr2

  • Guest
Re: Possible Bug: File not Recognized
« Reply #7 on: April 03, 2007, 07:51:58 pm »
Un-checking the link file boxes for all .h files did the trick. I am quite familiar with two phase of building an executable as I have taken an assembly class in Collage. The .gch files got me really confused as I have never seen them before. I understand that all .cpp and .h files are compiled into .o files then they are sent to the linker where they are assembled into one executable.

Btw, thanks for you help, I would have never figured this out on my own.

Cheers
Keith