Modulizing Help
Strange, here's my source files.
Problem Solved.
Please look below.
[Edited by - Tradone on April 23, 2006 3:51:42 PM]
edit:
Well, I think it's because skin.h contains control.h and control.h contains skin.h
g++ -c -g -O0 Skin.cpp -L/usr/local/lib -I/usr/local/include
In file included from Skin.h:10,
from Skin.cpp:1:
Control.h:53: error: ISO C++ forbids declaration of `Skin' with no type
Control.h:53: error: expected `;' before '*' token
*** Error code 1
Stop in /usr/home/david6327/httpdocs/shenu3.
145#
For some reason, Skin.cpp is being compiled before Control.cpp that may be a reason?
Everything compiles fine when I comment out Control.h in Skin.h
Well, I think it's because skin.h contains control.h and control.h contains skin.h
g++ -c -g -O0 Skin.cpp -L/usr/local/lib -I/usr/local/include
In file included from Skin.h:10,
from Skin.cpp:1:
Control.h:53: error: ISO C++ forbids declaration of `Skin' with no type
Control.h:53: error: expected `;' before '*' token
*** Error code 1
Stop in /usr/home/david6327/httpdocs/shenu3.
145#
For some reason, Skin.cpp is being compiled before Control.cpp that may be a reason?
Everything compiles fine when I comment out Control.h in Skin.h
http://www.gamedev.net/reference/programming/features/orgfiles/page3.asp
Okay it was problem #2 that I was experiencing. That was hell. Literally it ate up my whole day. Just trying to look for the right information. :(
Seriously, if I didn't find this link I had a 0.05% chance of figuring this out on my own.
[Edited by - Tradone on April 23, 2006 4:50:04 PM]
Okay it was problem #2 that I was experiencing. That was hell. Literally it ate up my whole day. Just trying to look for the right information. :(
Seriously, if I didn't find this link I had a 0.05% chance of figuring this out on my own.
[Edited by - Tradone on April 23, 2006 4:50:04 PM]
I am so tired.
I've been struggling for the rest of the day with this now:
Another friggin Modulizing problem.
g++ -o ShenuUpload.cgi -g -O0 ShenuUpload.o Algorithms.o DirectoryInformation.o Mime.o -L/usr/local/lib -I/usr/local/include -lcgicc
DirectoryInformation.o(.text+0xfc): In function `NOCASE_CMP::nocase_cmp(std::string const&, std::string const&)':
/usr/home/david6327/httpdocs/shenu3/CaseInsensitive.h:16: multiple definition of `NOCASE_CMP::nocase_cmp(std::string const&, std::string const&)'
ShenuUpload.o(.text+0xfc):/usr/home/david6327/httpdocs/shenu3/CaseInsensitive.h:16: first defined here
Please... help a poor young little soul.
I've been struggling for the rest of the day with this now:
Another friggin Modulizing problem.
g++ -o ShenuUpload.cgi -g -O0 ShenuUpload.o Algorithms.o DirectoryInformation.o Mime.o -L/usr/local/lib -I/usr/local/include -lcgicc
DirectoryInformation.o(.text+0xfc): In function `NOCASE_CMP::nocase_cmp(std::string const&, std::string const&)':
/usr/home/david6327/httpdocs/shenu3/CaseInsensitive.h:16: multiple definition of `NOCASE_CMP::nocase_cmp(std::string const&, std::string const&)'
ShenuUpload.o(.text+0xfc):/usr/home/david6327/httpdocs/shenu3/CaseInsensitive.h:16: first defined here
//CaseInsensitive.h#if !defined(CASEINSENSITIVE)#define CASEINSENSITIVE#include <string>#include <iostream>#include <map>class NOCASE_CMP{ public: static int nocase_cmp(const std::string & s1, const std::string& s2);};int NOCASE_CMP::nocase_cmp(const std::string & s1, const std::string& s2) { std::string::const_iterator it1=s1.begin(); std::string::const_iterator it2=s2.begin(); //stop when either string's end has been reached while ( (it1!=s1.end()) && (it2!=s2.end()) ) { if(::toupper(*it1) != ::toupper(*it2)) //letters differ? // return -1 to indicate smaller than, 1 otherwise return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; //proceed to the next character in each string ++it1; ++it2; } size_t size1=s1.size(), size2=s2.size();// cache lengths //return -1,0 or 1 according to strings' lengths if (size1==size2) return 0; return (size1<size2) ? -1 : 1;}#endif
Please... help a poor young little soul.
(Now that I'm thinking about it, is it legal to return a static variable?)
I think the error is because the declaration defines return as static, but the implementation doesn't use static. Try adding static on the implementation, or removing static on the declaration.
I think the error is because the declaration defines return as static, but the implementation doesn't use static. Try adding static on the implementation, or removing static on the declaration.
nocase_cmp is a global function
on the previous post I made my global function into a static method in a class in hopes that I can avoid the redeclaration error message, (it had to be static because I've read that static functions don't need an instance) but I still received the same error message like the one below whether the function was static or not. So I just changed it back into a global function. Please, help me.
145# make upload
g++ -c -g -O0 ShenuUpload.cpp -L/usr/local/lib -I/usr/local/include
g++ -c -g -O0 Algorithms.cpp -L/usr/local/lib -I/usr/local/include
g++ -c -g -O0 DirectoryInformation.cpp -L/usr/local/lib -I/usr/local/include
g++ -c -g -O0 Mime.cpp -L/usr/local/lib -I/usr/local/include
g++ -o ShenuUpload.cgi -g -O0 ShenuUpload.o Algorithms.o DirectoryInformation.o Mime.o -L/usr/local/lib -I/usr/local/include -lcgicc
DirectoryInformation.o(.text+0xfc): In function `nocase_cmp(std::string const&, std::string const&)':
/usr/home/david6327/httpdocs/shenu3/CaseInsensitive.h:11: multiple definition of `nocase_cmp(std::string const&, std::string const&)'
ShenuUpload.o(.text+0xfc):/usr/home/david6327/httpdocs/shenu3/CaseInsensitive.h:11: first defined here
*** Error code 1
edit2: when I search c++ modulization or c++ module, I am not getting the correct matches that I want. I guess they're called dependencies?
I'm not getting matches for dependencies either, can anybody please at least give me a search word? Thanks plenty, for helping a poor young soul.
edit3: Okay, so was actually reading http://www.gamedev.net/reference/programming/features/orgfiles/page4.asp for the 10th time. This time not skimming through it but actually reading it.
my main.cpp which is ShenuUpload.cpp includes the header file DirectoryInformation.h. DirectoryInformation.cpp also contains the header DirectoryInformation.h. DirectoryInformation.h includes the global function nocase_cmp. Later, ShenuUpload.o and DirectoryInformation.o is linked. That is why I am getting the error it seems. It seems like problem #3 described from the above link.
edit4: I fixed it. It was actually problem#4 in the above link. I was defining the function inside CaseInsensitive.h. Instead I pulled out the function into its own CaseInsensitive.cpp file and recompiled and it worked. That was really frustrating as hell. I still can't believe it took me a whole day to realize this. I'm gonna have to learn how to read more carefully next time instead of skimming through them :)
Well, thanks gameDev for providing such links.
Now I fully understand all 4 problems. and they are all common problems in modulizing your files.
This is the final result:
[Edited by - Tradone on April 24, 2006 11:17:39 AM]
on the previous post I made my global function into a static method in a class in hopes that I can avoid the redeclaration error message, (it had to be static because I've read that static functions don't need an instance) but I still received the same error message like the one below whether the function was static or not. So I just changed it back into a global function. Please, help me.
#if !defined(CASEINSENSITIVE)#define CASEINSENSITIVE#include <string>#include <iostream>#include <map>int nocase_cmp(const std::string & s1, const std::string& s2);int nocase_cmp(const std::string & s1, const std::string& s2) { std::string::const_iterator it1=s1.begin(); std::string::const_iterator it2=s2.begin(); //stop when either string's end has been reached while ( (it1!=s1.end()) && (it2!=s2.end()) ) { if(::toupper(*it1) != ::toupper(*it2)) //letters differ? // return -1 to indicate smaller than, 1 otherwise return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; //proceed to the next character in each string ++it1; ++it2; } size_t size1=s1.size(), size2=s2.size();// cache lengths //return -1,0 or 1 according to strings' lengths if (size1==size2) return 0; return (size1<size2) ? -1 : 1;}struct case_insensitive_test{ bool operator () (const std::string &a_str, const std::string &b_str) const{ std::string::const_iterator a(a_str.begin()), b(b_str.begin()); unsigned int a_value = 0, b_value = 0; if(a == a_str.end()) // a_str is empty. . . return b != b_str.end(); // if b_str isn't empty, then a_str is less then b_str, otherwise they're equal. if(b == b_str.end()) // b_str is empty. . . return false; // Since a_str isn't empty, a_str isn't less then b_str. for(; a != a_str.end(); ++a) if(*a >= '0' && *a <= '9') // If a_str has a numeric character. . . a_value = a_value*10+*a-'0'; else // Otherwise, it must be a string. { for(; b != b_str.end(); ++b) if(*b < '0' || *b > '9') // If b_str contains characters that aren't numeric. . . return nocase_cmp(a_str, b_str) < 0; // Compare them as strings. return false; // Otherwise, a_str isn't less than b_str, since b_str is a string and a_str isn't. } // At this point, we know a_str is a number and have it's value calculated. for(; b != b_str.end(); ++b) if(*b >= '0' && *b <= '9') // If b_str has a numeric character. . . b_value = b_value*10+*b-'0'; else // Otherwise, it must be a string. . . return true; // Since a_str is a number, a_str must be less than b_str. // Since they're both numbers, compare their values. . . return a_value < b_value; }};#endif
145# make upload
g++ -c -g -O0 ShenuUpload.cpp -L/usr/local/lib -I/usr/local/include
g++ -c -g -O0 Algorithms.cpp -L/usr/local/lib -I/usr/local/include
g++ -c -g -O0 DirectoryInformation.cpp -L/usr/local/lib -I/usr/local/include
g++ -c -g -O0 Mime.cpp -L/usr/local/lib -I/usr/local/include
g++ -o ShenuUpload.cgi -g -O0 ShenuUpload.o Algorithms.o DirectoryInformation.o Mime.o -L/usr/local/lib -I/usr/local/include -lcgicc
DirectoryInformation.o(.text+0xfc): In function `nocase_cmp(std::string const&, std::string const&)':
/usr/home/david6327/httpdocs/shenu3/CaseInsensitive.h:11: multiple definition of `nocase_cmp(std::string const&, std::string const&)'
ShenuUpload.o(.text+0xfc):/usr/home/david6327/httpdocs/shenu3/CaseInsensitive.h:11: first defined here
*** Error code 1
edit2: when I search c++ modulization or c++ module, I am not getting the correct matches that I want. I guess they're called dependencies?
I'm not getting matches for dependencies either, can anybody please at least give me a search word? Thanks plenty, for helping a poor young soul.
edit3: Okay, so was actually reading http://www.gamedev.net/reference/programming/features/orgfiles/page4.asp for the 10th time. This time not skimming through it but actually reading it.
my main.cpp which is ShenuUpload.cpp includes the header file DirectoryInformation.h. DirectoryInformation.cpp also contains the header DirectoryInformation.h. DirectoryInformation.h includes the global function nocase_cmp. Later, ShenuUpload.o and DirectoryInformation.o is linked. That is why I am getting the error it seems. It seems like problem #3 described from the above link.
edit4: I fixed it. It was actually problem#4 in the above link. I was defining the function inside CaseInsensitive.h. Instead I pulled out the function into its own CaseInsensitive.cpp file and recompiled and it worked. That was really frustrating as hell. I still can't believe it took me a whole day to realize this. I'm gonna have to learn how to read more carefully next time instead of skimming through them :)
Well, thanks gameDev for providing such links.
Now I fully understand all 4 problems. and they are all common problems in modulizing your files.
This is the final result:
//CaseInsensitive.h#if !defined(CASEINSENSITIVE)#define CASEINSENSITIVE#include <string>#include <iostream>#include <map>int nocase_cmp(const std::string & s1, const std::string& s2);struct case_insensitive_test{ bool operator () (const std::string &a_str, const std::string &b_str) const{ std::string::const_iterator a(a_str.begin()), b(b_str.begin()); unsigned int a_value = 0, b_value = 0; if(a == a_str.end()) // a_str is empty. . . return b != b_str.end(); // if b_str isn't empty, then a_str is less then b_str, otherwise they're equal. if(b == b_str.end()) // b_str is empty. . . return false; // Since a_str isn't empty, a_str isn't less then b_str. for(; a != a_str.end(); ++a) if(*a >= '0' && *a <= '9') // If a_str has a numeric character. . . a_value = a_value*10+*a-'0'; else // Otherwise, it must be a string. { for(; b != b_str.end(); ++b) if(*b < '0' || *b > '9') // If b_str contains characters that aren't numeric. . . return nocase_cmp(a_str, b_str) < 0; // Compare them as strings. return false; // Otherwise, a_str isn't less than b_str, since b_str is a string and a_str isn't. } // At this point, we know a_str is a number and have it's value calculated. for(; b != b_str.end(); ++b) if(*b >= '0' && *b <= '9') // If b_str has a numeric character. . . b_value = b_value*10+*b-'0'; else // Otherwise, it must be a string. . . return true; // Since a_str is a number, a_str must be less than b_str. // Since they're both numbers, compare their values. . . return a_value < b_value; }};#endif//CaseInsensitive.cpp#include "CaseInsensitive.h"int nocase_cmp(const std::string & s1, const std::string& s2) { std::string::const_iterator it1=s1.begin(); std::string::const_iterator it2=s2.begin(); //stop when either string's end has been reached while ( (it1!=s1.end()) && (it2!=s2.end()) ) { if(::toupper(*it1) != ::toupper(*it2)) //letters differ? // return -1 to indicate smaller than, 1 otherwise return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; //proceed to the next character in each string ++it1; ++it2; } size_t size1=s1.size(), size2=s2.size();// cache lengths //return -1,0 or 1 according to strings' lengths if (size1==size2) return 0; return (size1<size2) ? -1 : 1;}
[Edited by - Tradone on April 24, 2006 11:17:39 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement