|
I'm "damn sure". And don't "guess" - know. And I can't make it a DLL (if I did, the DLL and the EXE would both be huge, which is the opposite of my main goal). It is a static library linked against the final EXE as demonstrated by my original post.
Only people who have experienced the problem I've got should be replying - really large libraries used across multiple solutions and projects that are including 'static' functions that are never referenced. You apparently don't fall into that category.
Also, I just discovered a set of static functions in the final EXE that are in a class that is completely unrelated to the program itself (NT Service related functions - and the program is not a NT Service nor makes any calls into the class that has those support functions).
|
|
|
|
|
What about a static library?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Huh? Notice the .lib and .exe split of the original post. The .lib file IS a static library linked against the final .exe.
|
|
|
|
|
Well, you are right. I made also a test and the result, on Debug built, confirm your original post. On the other hand, on a Release build, the result, as far as I can understand, appears different.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Well, of course. Debug builds include everything (even unused code). In order to see what I'm talking about, it has to be a Release build with program database generation (/Zi, adds about 32 extra bytes to the final EXE but necessary for various things) and you need to be using a static code disassembler (e.g. IDA Pro). In other words, you need to set up your dev. environment so you can reverse-engineer the EXE (binary file) to see what I'm talking about.
BTW, I compiled the simplest EXE possible (console program, displays "Hello") in Release mode and it generates a 160K file with the library, a 56K file without. It should be about 60K. There is 100K of unnecessary code being included.
|
|
|
|
|
Did you try with a pure C library?
Anyway the linker behaviour you discovered is, IMHO, really disappointing.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
This isn't a bug. This is physical coupling. The library modules are mixing the different classes together. In this case, the module that contains the static class function C::Func1() also contains the definition of B::Func2(). That function will drag in all of classes A and B.
If you want the library to generate a small footprint, you need to minimize the physical coupling. Separate the classes into distinct modules. In this case you can simply create a separate file to hold C::Func1(). Have the linker generate the map file and check the symbols and modules being included. You can get incremental improvements here so you don't have to do everything at once.
|
|
|
|
|
I look for code with dilog applicaton in vc6 help plz.
|
|
|
|
|
|
you could try looking at books like "Learn microsoft visual c++ in 21 days"
this one is excellent
|
|
|
|
|
I have two different dialog based VC++ project called Main and sub.
When a OK button of Main project is clicked I want Dialogbox of Sub to be executed.
I have inserted sub.dsp into MAIN workspace. Made Sub dependent of Main.
Included "sub.h" & "subDlg.h" into "MainDlg.h"
Declared CSubDlg into CMainDlg.
When compiled I am getting an LNK 2001 Unresolved External Symbols Error.
Help to resolve.
Thanks,
Bala.
bala_potty
|
|
|
|
|
I guess you need to learn the basics of build systems and the entities project and workspace. adding a project to workspace containing the main project and setting the dependency doesnot include the definition of functions or variables to the main project whose symbols are still considered unresolved at the linking stage of main project. If you are looking Main and Sub to be combined as single application you can make the sub as library project and link the sublibrary statically or dynamically yo the main project. Or add all the source files to the main project making it a single project. Or Main and sub as separate app and use IPC to interface each other.
In your case i think you just add all the source files to main project and build it.
|
|
|
|
|
Thank you Raj, But when I tried add all the source files of SUB to main project and buid it the .rc file of SUB is not getting Compiled.
Is there anyway this can be resolved?
Infact both MAIN & SUB are MFC AppWizard build .EXE projects. Pl. let me Know how to Convert SUB into DLL. so that Main and Sub to be combined as single application. Your suggestion will be of great help to me.
bala_potty
|
|
|
|
|
|
Got it Thanks.
bala_potty
|
|
|
|
|
In the below example, I just push some pointers to objects of type myClass into the vector. Previously, When I pushed just the objects as such, the find algo worked with the overloaded "==". But it's now pointers inside the vector. And I want the find algo still to find it, with integer as the passed argument for it. How can I do it?
class myClass
{
public:
int x;
int y;
bool operator == (const int& n)
{
cout<<"\nCheck";
cout<<"\n"<<n<<"\t"<<x;
return(n==x);
}
};
std::vector<myClass*> vec_myClass;
myClass* obj = new myClass();
obj->x=1;
obj->y=1;
vec_myClass.push_back(obj);
myClass* obj2= new myClass();
obj2->x=2;
obj2->y=2;
vec_myClass.push_back(obj2);
int n=2;
vector<myClass*>::iterator itr_vec = vec_myClass.begin();
itr_vec =std::find(vec_myClass.begin(),vec_myClass.end(),n);
<br />
itr_vec =std::find(vec_myClass.begin(),vec_myClass.end(),n); <br />
Here it's not taking "n" , and I can also guess why isn't taking. It actually expects an overload of == where we pass a pointer to the object itself. Is there anyway I can do it? Just by passing int?
----------------------------
286? WOWW!
modified on Saturday, March 15, 2008 1:37 PM
|
|
|
|
|
_8086 wrote: It actually expects an overload of == where we pass a pointer to the object itself. Is there anyway I can do it? Just by passing int?
Atleast one formal parameter of operators must be of non pointer class type, otherwise you can simply add a global operator == for type "myClass *" and int. But you can achieve it very easily with a another class which exposes the overloaded operator.
say,
class CSearchKey
{
public:
int m_iVal;
CSearchKey(int iVal)
:m_iVal (iVal)
{
};
};
inline bool operator == (const myClass *pObj, const CSearchKey &rKey)
{
return(*pObj==rKey.m_iVal);
}
And in your original code you only want to change as follows.
itr_vec =std::find(vec_myClass.begin(),vec_myClass.end(),CSearchKey(n));
hope this solves.
|
|
|
|
|
Hello Rajkumar, thanks for your effort. I get these following errors. How did you manage to compile? I'm using VC8.0
error C2804: binary 'operator ==' has too many parameters
error C2333: 'myClass::operator ==' : error in function declaration; skipping function body
The whole program:
class CSearchKey
{
public:
int m_iVal;
CSearchKey(int iVal)
:m_iVal (iVal)
{
};
};
class myClass
{
public:
int x;
int y;
inline bool operator == (const myClass *pObj, const CSearchKey &rKey)
{
return(*pObj==rKey.m_iVal);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<myClass*> vec_myClass;
myClass* obj = new myClass();
obj->x=1;
obj->y=1;
vec_myClass.push_back(obj);
myClass* obj2= new myClass();
obj2->x=2;
obj2->y=2;
vec_myClass.push_back(obj2);
int n=2;
vector<myClass*>::iterator itr_vec = vec_myClass.begin();
itr_vec =std::find(vec_myClass.begin(),vec_myClass.end(),CSearchKey(n));
if(itr_vec!=vec_myClass.end())
cout<<"\n\nResult:"<<(*itr_vec)->x<<"\n\n";
return 0;
}
----------------------------
286? WOWW!
|
|
|
|
|
the newly suggested operator is to be in global scope not in the class myclass, and you commented the already existing operator but that is used in the global == operator. Don't you see == operator takes multiple parameter its not a class member.
keep your code unchanged, don't comment the == operator in myclass. then the move the inline == operator to global, just below the CSearchKey class, use it in a header so that if you are using it in multiple cpp file this becomes inline and no additional code is generated for this. only thing you have to modify in your original code is whenever you search for int n search with CSearchKey(n). Try and let me know.
|
|
|
|
|
Great that's works! Thanks a lot. But why is not taking int as a parameter for == ? What harms it?
For example,
<br />
inline bool operator == (const myClass *pObj,const int& n)<br />
{ <br />
return(pObj->x==n);<br />
}<br />
itr_vec =std::find(vec_myClass.begin(),vec_myClass.end(),n);<br />
instead of,
<br />
inline bool operator == (const myClass *pObj,const CSearchKey &rKey)<br />
{ <br />
return(return(pObj->x ==rKey.m_iVal););<br />
}<br />
itr_vec =std::find(vec_myClass.begin(),vec_myClass.end(),CSearchKey(n));<br />
Why does it require a paramter of class type??
operator ==' must have at least one formal parameter of class type
I dont understand this requirement.
----------------------------
286? WOWW!
|
|
|
|
|
if both parameters are pointers or primitive types it takes pure comparison of values. (int and void *).
_8086 wrote: But why is not taking int as a parameter for == ?
you can have wrapper for "myClass *", ptrMyClass as we did for int, CSearchKey.
then inline bool operator == (const myClass *pObj,const int& n) can be used as
inline bool operator == (const ptrMyClass &ptrObj,const int& n) but then you have to store in vector as vector<ptrmyclass>.
|
|
|
|
|
Hello everyone,
Any ideas why Pimpl idiom is called "Compilation Firewalls"?
http://www.gotw.ca/gotw/024.htm
I have thought for a while, and I think client code does not need to compile in Pimpl idiom, so like a firewall to block compile, it is called "Compilation Firewalls".
Any ideas why it is named "Compilation Firewalls"?
thanks in advance,
George
|
|
|
|
|
Probably because Herb Sutter (the author of GoTW) liked it ?
pimpl, when well executed, will prevent (thus a "firewall" or insulating) a lot of dependent re-compilation when the private implementation
of a class changes.
dependent of a class should never, in the best case, know the private implementation of a class; I've even seen some design that put all private methods as free functions in the code.
|
|
|
|
|
Thanks Maximilien,
Question answered.
regards,
George
|
|
|
|
|
Hello,
I am naive to Windows Services.
I have few queries regarding Windows Services which are as follows: -
How to manage User account?
For example there are several users present on a single machine and how to restrict users group from accessing the Windows Service?
Can do it using CoInitializeSecutriy(), if yes then How?
Thanks in Advance.
|
|
|
|