|
|
Home » U++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » problem with compilation/linking - Duplicate .cpp file in single package
problem with compilation/linking - Duplicate .cpp file in single package [message #11461] |
Fri, 14 September 2007 02:16 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
Hello, I'm trying to use UnitTest++ in my project ( http://unittest-cpp.sourceforge.net/ ) and to create a UPP package from it.
But I have run into the limited UPP builder ...
The source contain two files with the same name:
src/Posix/TimeHelpers.cpp
src/Win32/TimeHelpers.cpp
Only one of them should be used during compile, chosen by the target platform.
There's no problem to add #ifdef PLATFORM_WIN32 into that cpp file, so the cpp will compile without problem.
But during linking the linker gets the same .o twice, thus reporting multiple definitions of some code.
I think the .o file names should reflect that those are two different files, and produce two different .o files (like TimeHelpers.o and TimeHelpers(2).o ?? or srcPosixTimeHelpers.o srcWin32TimeHelpers.o (directory path added as prefix to .o file name? This can still lead to duplicity, if somebody has directory structure .../a/a and .../aa .. so this one will not work, the UPP must cleanly recognize all duplicity and resolve it with generated names which don't conflict ) )
Anyway, IMO another correct solution is to add "exclude from build WHEN" to package settings, so I can exclude the Win32 files on !PLATFORM_WIN32 and exclude the Posix files when on PLATFORM_WIN32.
This still does not solve cpp files with same name in different directories, but it would solve my problem and IMHO it makes sense so You don't need those ugly #ifdef in code, but you can omit whole cpp from building process by flags.
Another problem I run into is that I can't enter "+" into package name when creating new package. I had to edit the dir and .upp files manually on disk to get "UnitTest++" package name.
|
|
|
|
|
|
Re: problem with compilation/linking - Duplicate .cpp file in single package [message #11602 is a reply to message #11598] |
Tue, 18 September 2007 21:40 |
Zardos
Messages: 62 Registered: April 2007
|
Member |
|
|
Well, if it is all about a Unittest package you can probably write one which would fit perfectly into U++.
I have attached a zip-file containing 3 files. UTest.cpp, UTest.h and _Test_.cpp
_Test_.cpp shows an example how to use it.
Basically there are:
UTest(testname) {
}
UModule(modulename) {
int var1;
XY *xy;
UInit(modulename) { // Initialize a module
xy = new XY;
}
UTerm(modulename) { // Terminate a module
delete xy;
}
... following UTest(..) "functions" probably using var1 and xy
}
// to be used inside UTest(...)
UCheck(expression) // checks if an expression evaluates to true (ASSERT for UTest)
UExcept(ExectionClass, functioncall) // checks if an exception is thrown
UTiming(seconds) {// checks if a function executes in a given time
// Block which gets messured
}
These files work not out of the box with U++!!!!
You have to rewrite some functions with the U++ classes and functions. But all in all it's just 160 lines... So it can probably done in 20 minutes.
Basically replace Vec with Vector. replace the foreach(e, c) loops with the U++ style iteration: for(int i = 0, i < ...). Change the Logging functions: Err/Inf to the U++ logging functions and finally replace the Timing class Timer with the U++ version.
Ahh and you have to call RunUTests() somewhere
If I have a little bit time tomorrow I can do it for you. I'm currently just playing around with some other stuff, so it's not in U++ this time.
-
Attachment: UTest.zip
(Size: 2.18KB, Downloaded 259 times)
[Updated on: Tue, 18 September 2007 21:42] Report message to a moderator
|
|
|
Re: problem with compilation/linking - Duplicate .cpp file in single package [message #11603 is a reply to message #11461] |
Wed, 19 September 2007 00:06 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
It's not about UnitTest package (I hacked it "to work" within minutes, see http://www.ultimatepp.org/forum/index.php?t=msg&th=1156& amp;start=0& for ready-to-use package).
It's about how to do it in "right way" (and with minimal changes to the 3rd party source), and about my wishes what I miss in Ultimate tool chain.
My current version can't be simply updated to newer one just by replacing sources, all those little changes must be preserved whenever I will upgrade it to newer version. So adding such feature into TheIDE would both bring down the amount of changes needed, and it would also add a feature which I feel is missing (yet I don't have any other source which would take advantage of it, that's the reason why I say "feel").
I think the Core itself would benefit a little bit from it too, so some .cpp files (like Core/Win32Com.cpp) can be without #ifdef on the beginning and end, simply excluded completely from build process on different platforms.
|
|
|
Goto Forum:
Current Time: Sat May 04 17:52:59 CEST 2024
Total time taken to generate the page: 0.02754 seconds
|
|
|