User forums > Help

Precompiled Header Hell

<< < (2/2)

Urxae:

--- Quote from: sviten on December 02, 2005, 01:14:04 am ---
--- Code: ---[...]
mingw32-g++.exe [...] protocol.h.gch .objs\sha256.o sha256.h.gch [...]
mingw32-g++.exe: protocol.h.gch: No such file or directory
mingw32-g++.exe: sha256.h.gch: No such file or directory
Process terminated with status 1 (0 minutes, 11 seconds)
0 errors, 0 warnings

--- End code ---

--- End quote ---
You're passing precompiled headers to the linker :shock:? Go to the dialog you posted the screenshot from, first tab, is "Link file" checked? That should never be checked for headers. (check both protocol.h and sha256.h)
If it isn't (though it probably is, due to the order on the command line), check in all locations where you can specify linker options (Project -> Build options, for every item in the tree to the left, linker tab and Settings -> Compiler, also linker tab) and see if you specified protocol.h.gch and sha256.h.gch anywhere. Remove them.

rickg22:
Hint: Disable BOTH the "link" and the "compile" flag to your header files. That way you WON'T have to use precompiled headers *AT ALL*.

sviten:
OK, that reduced it to some errors that I'm more familiar with...


--- Code: ---Project   : Console application
Compiler  : GNU GCC Compiler (called directly)
Directory : D:\Projects\GeccoTester\
--------------------------------------------------------------------------------
Switching to target: default
mingw32-g++.exe   -LD:\Projects\GeccoTester\ -L..\ptypes-2.0.2\lib  -L"d:\Program Files\CodeBlocks\lib" -LD:\Projects\ptypes-2.0.2\lib -o D:\Projects\GeccoTester\GeccoTester.exe .objs\protocol.o .objs\sha256.o .objs\main.o        ..\ptypes-2.0.2\lib\libptypes.a
.objs\protocol.o: In function `ZN21AccountRequestMessage6assignEPKcj':
D:/Projects/GeccoTester/protocol.cpp:58: undefined reference to `sha256_starts(sha256_context*)'
D:/Projects/GeccoTester/protocol.cpp:59: undefined reference to `sha256_update(sha256_context*, unsigned char*, unsigned long)'
D:/Projects/GeccoTester/protocol.cpp:60: undefined reference to `sha256_finish(sha256_context*, unsigned char*)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)
3 errors, 0 warnings

--- End code ---

However, I don't understand why I'm getting linker errors here since I've properly included " #include"protocol.h"  as well as put the current project directory in the linker path.  Any ideas?

Urxae:

--- Quote from: sviten on December 02, 2005, 02:00:00 am ---
--- Code: ---[...]
mingw32-g++.exe   -LD:\Projects\GeccoTester\ -L..\ptypes-2.0.2\lib  -L"d:\Program Files\CodeBlocks\lib" -LD:\Projects\ptypes-2.0.2\lib -o D:\Projects\GeccoTester\GeccoTester.exe .objs\protocol.o .objs\sha256.o .objs\main.o        ..\ptypes-2.0.2\lib\libptypes.a
.objs\protocol.o: In function `ZN21AccountRequestMessage6assignEPKcj':
D:/Projects/GeccoTester/protocol.cpp:58: undefined reference to `sha256_starts(sha256_context*)'
D:/Projects/GeccoTester/protocol.cpp:59: undefined reference to `sha256_update(sha256_context*, unsigned char*, unsigned long)'
D:/Projects/GeccoTester/protocol.cpp:60: undefined reference to `sha256_finish(sha256_context*, unsigned char*)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)
3 errors, 0 warnings

--- End code ---

--- End quote ---

Those errors basically mean "AccountRequestMessage::assign(char const*, unsigned int) is using three functions that have been declared but aren't defined in any (linked) object file".
Judging by their names, I'd assume they were supposed to be in sha256.cpp. See if they are defined there, and if their signature is exactly the same (incuding constness etc.).
Another possibility that just occurred to me: these look like C functions (sha256_ prefix, char*'s). If they're actually defined in a .c file, that might also explain it: C++ uses a different naming scheme than C by default. The fix would be to either rename the file to have an extension associated with C++ (.cpp is the most popular AFAIK), specify '-x c++' as an additional command-line option for these files, or change the header associated with it to be similar to this:

--- Code: ---#ifndef SOME_HEADER_GUARD
#define SOME_HEADER_GUARD

#ifdef __cplusplus
extern "C" {
#endif

/* * * The rest of the original header * * */

#ifdef __cplusplus
} // extern "C"
#endif

#endif // SOME_HEADER_GUARD
--- End code ---
(you can also put extern "C" in front of each and every declaration your C++ program uses, but that's probably more work)

sviten:
Bingo.  It was the .c extension.

Thanks so much for your help.

Navigation

[0] Message Index

[*] Previous page

Go to full version