Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ TheIDE » U++ TheIDE: Other Features Wishlist and/or Bugs » cpp/icpp name clashes [BUG?]
cpp/icpp name clashes [BUG?] [message #25649] Sat, 06 March 2010 02:25 Go to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hello!
I just realized, that having package with .cpp and .icpp file of the same name leads to error, because the second object file rewrites the first. I'm not sure if it can be called a bug, but I think it should be at least mentioned somewhere in the documentation. Solution to this could be using different name or separate folder when compiling icpp files... Simple testcase follows:

File test.cpp:
#include <Core/Core.h>
using namespace Upp;
extern int test;

CONSOLE_APP_MAIN{
	Cout()<<"test: "<<test<<"\n";
}
File test.icpp:
#include <Core/Core.h>
using namespace Upp;

int test;
INITBLOCK{test=1;}
This fails to link, but if you rename one of the files, it works as expected.

Best regards,
Honza
Re: cpp/icpp name clashes [BUG?] [message #25655 is a reply to message #25649] Sat, 06 March 2010 14:30 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

PS: As Sender Ghost pointed out to me in a personal conversation, this problem also applies in case of .c and .cpp files with same name, which is I think even more probable to happen.
Re: cpp/icpp name clashes [BUG] [message #25658 is a reply to message #25649] Sat, 06 March 2010 17:43 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello, Jan.

I created attached patch to review, which solves mentioned problem. It can be applied for ide/Builders directory.

The main idea is to add file name with extension to object name.
As readers can see, the U++ developer(s) aware about this problem with rc and brc extensions, but they don't expand it for this problem with more simple solution.

Edit:
The contents of description and patch was changed.

[Updated on: Sun, 07 March 2010 14:31]

Report message to a moderator

Re: cpp/icpp name clashes [BUG] [message #25777 is a reply to message #25658] Thu, 11 March 2010 14:51 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I do not know, this issue was around always... I guess it might be better to avoid such clashes, otherwise this can cause problems e.g. in makefiles...
Re: cpp/icpp name clashes [BUG] [message #25794 is a reply to message #25777] Thu, 11 March 2010 22:30 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
This is simple. I found this solution when used CMake generated make files for LLVM project.
Now, TheIDE will compile FileName.cpp to FileName.obj object file. CMake generated make file will compile it to FileName.cpp.obj. No more extension clashes in last case.
This is only one operation in the Builders code:
Changing GetFileTitle(fn) to GetFileName(fn) function where object file will be created.
Re: cpp/icpp name clashes [BUG] [message #25798 is a reply to message #25794] Fri, 12 March 2010 10:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sender Ghost wrote on Thu, 11 March 2010 16:30

This is simple. I found this solution when used CMake generated make files for LLVM project.
Now, TheIDE will compile FileName.cpp to FileName.obj object file. CMake generated make file will compile it to FileName.cpp.obj. No more extension clashes in last case.
This is only one operation in the Builders code:
Changing GetFileTitle(fn) to GetFileName(fn) function where object file will be created.


I am sorry for perhaps too much thinking about the issue... Still, if you put a file to compiler in commandline, it just replaces the extension with ".o" (or ".obj"). So the proposed change is diverging from this practice.

But I think very likely I will do it as you suggest.

Mirek
Re: cpp/icpp name clashes [BUG] [message #25801 is a reply to message #25798] Fri, 12 March 2010 10:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Maybe only for extensions that are not .cpp? Smile
Re: cpp/icpp name clashes [BUG] [message #25803 is a reply to message #25801] Fri, 12 March 2010 12:24 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

luzr wrote on Fri, 12 March 2010 10:58

Maybe only for extensions that are not .cpp? Smile

And what if someone is stupid enough to have files "file.c" and "file.c.cpp"? Very Happy (This post is mostly a joke... Wink )

Honza
Re: cpp/icpp name clashes [BUG] [message #25805 is a reply to message #25798] Fri, 12 March 2010 15:43 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
luzr wrote on Fri, 12 March 2010 10:15

Still, if you put a file to compiler in commandline, it just replaces the extension with ".o" (or ".obj"). So the proposed change is diverging from this practice.


Exists problem with 8.3 file name for FAT file system.
Anyway, most compilers have option to output object file to different file name.
Re: cpp/icpp name clashes [BUG] [message #25806 is a reply to message #25805] Fri, 12 March 2010 15:55 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
FAT is dead. Please don't make any design decision based possible FAT. You would only delay FAT's transition from dead to dead and forgotten Smile.
Re: cpp/icpp name clashes [BUG] [message #25807 is a reply to message #25806] Fri, 12 March 2010 16:34 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
I just tried to explain possible compiler design decision.

The correct answers appear after testing the proposed changes.
This discussion reminds me about the candle problem. And excuse me for possible comparison. This is just an example.
Re: cpp/icpp name clashes [BUG] [message #25810 is a reply to message #25806] Fri, 12 March 2010 21:15 Go to previous messageGo to next message
andrei_natanael is currently offline  andrei_natanael
Messages: 262
Registered: January 2009
Experienced Member
cbpporter wrote on Fri, 12 March 2010 16:55

FAT is dead. Please don't make any design decision based possible FAT. You would only delay FAT's transition from dead to dead and forgotten Smile.

FAT's not so dead Sad Today i had problems with it on one of my flash memories because FAT32 doesn't allow files bigger than 4GB.
I should try exFAT but i don't know how compatible is that with Linux. It's pity that Windows doesn't support ext4 Rolling Eyes
Re: cpp/icpp name clashes [BUG] [message #25815 is a reply to message #25810] Sat, 13 March 2010 16:30 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
FAT is dead. FAT32 is very much alive. Format it as NTFS, but your performance with small files will suffer a lot.
Re: cpp/icpp name clashes [BUG] [message #25839 is a reply to message #25805] Mon, 15 March 2010 03:57 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Question:
How GCC, MSC, OW, CLANG compilers will assemble following source code consisted of FileName, FileName.cpp, FileName.h, FileName.icpp, main.cpp files?
Answer:
GCC input:
gcc -x c++ FileName FileName.cpp FileName.icpp main.cpp

GCC output files:
a.exe

MSC input:
cl /nologo /TP FileName FileName.cpp FileName.icpp main.cpp

MSC output:
FileName
FileName.cpp
FileName.icpp
main.cpp
Generating Code...
FileName.obj : warning LNK4042: object specified more than once; extras ignored
FileName.obj : warning LNK4042: object specified more than once; extras ignored
main.obj : error LNK2019: unresolved external symbol "int __cdecl ICppFunction(void)" (?ICppFunction@@YAHXZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "int __cdecl CppFunction(void)" (?CppFunction@@YAHXZ) referenced in function _main
FileName.exe : fatal error LNK1120: 2 unresolved externals

OW input:
wcl386 -zq -cc++ FileName FileName.cpp FileName.icpp main.cpp

Some OW output:
Error! E2028: int near Function() is an undefined reference
Error! E2028: int near ICppFunction() is an undefined reference
file MAIN.obj(C:\MAIN.CPP): undefined symbol int near Function()
file MAIN.obj(C:\MAIN.CPP): undefined symbol int near ICppFunction()
Error: Linker returned a bad status

CLANG input:
clang -x c++ FileName FileName.cpp FileName.icpp main.cpp

CLANG output files:
a.out

Conclusion:
Some compilers can resolve extension clashes internally, but others only with output renaming.

Notes:
For testing used following tools:
gcc (TDM-2 mingw32) 4.4.1
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Open Watcom C/C++32 Compile and Link Utility Version 1.9beta1 LA
clang version 1.1 (trunk 98527)

Source code:
File FileName:
#include "FileName.h"

int Function()
{
	return 0;
}

File FileName.cpp:
#include "FileName.h"

int CppFunction()
{
	return 1;
}

File FileName.h:
#ifndef __FileName_h__
#define __FileName_h__

int Function();
int CppFunction();
int ICppFunction();

#endif

File FileName.icpp:
#include "FileName.h"

int ICppFunction()
{
	return 2;
}

File main.cpp:
#include "FileName.h"

int main()
{
	int result = Function() + CppFunction() + ICppFunction();

	return result; // 3
}
Re: cpp/icpp name clashes [BUG] [message #26136 is a reply to message #25839] Mon, 05 April 2010 11:35 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Many would consider this as something a programmer should be aware of rather than an IDE/compiler bug.

Why would someone need/want to have the file names the same except for the extension???

C++ has reserved words for a purpose, the same concept for file names that make up a package, application, library, includes, etc. would seem to make sense.

Whether the extension is .c, .cpp, .icpp, .o, .obj, .h, .dll or whatever
it should relate to the same "FileName". My mind is a bit slow on some things, having it otherwise would make my head hurt.

"FAT32 is very much alive"

[Updated on: Mon, 05 April 2010 12:10]

Report message to a moderator

Re: cpp/icpp name clashes [BUG] [message #26137 is a reply to message #26136] Mon, 05 April 2010 12:21 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Well, I admit that it is something that good programmer should know and be aware of. It's just that I'm not that good and I'm also quite lazy Smile And I also found another name clash problem, this time even less noticeable. Let me show you on example:

Suppose I want to use libfoo with U++, so I decide to create a package plugin/foo. It is quite logical to put the wrapper code into plugin/foo/foo.cpp. Now I will copy the original sources into plugin/foo/lib subdirectory. It is quite likely that there will be a file plugin/foo/lib/foo.c. I wouldn't expect at all, that file with same name, but different extension and in different directory (!) may cause troubles. Yet it will fail to compile in theide...

The different directory problem is not related to the original post, but these two combined can make it much more confusing.

About FAT: You are right, FAT32 is alive. But it has no 8.3 problem. Long filenames were introduced into FAT in Win95. That means this problem doesn't exist anymore.

Regards,
Honza
Previous Topic: theIDE crashes on win32 since revision 2221
Next Topic: batch build
Goto Forum:
  


Current Time: Thu Mar 28 21:23:13 CET 2024

Total time taken to generate the page: 0.01544 seconds