Link to home
Start Free TrialLog in
Avatar of pigangel
pigangel

asked on

Problem with insert another project to current workspace

Hello, Experts:
   I need your help urgently!

   I download a free project which build a very useful LIB and like to use it in my project A, I had tried the demo program which the author provided how to use that free porject, it runs very well, and I create a new  project B to test again, and the test was sucessful. now I am tryint to use in my project A, but I encountered a problem. my problem is :

----- problem -----
   when I insert the free project to my project B workspace, and set the dependency(my project B is dependent on the the free project), and also link the output LIB and add the free project directory to additional include directories. so I can see those Header files in free project in External dependences list of my project B.

   I did the same thing to my project A,and I ensured the the setting of project A and project B is the same.
 BUT I can not see those Header files inside free project  in External dependences list of my project A. so when I try to use a class defined in that LIB header file, even I had manual inlcude the hearder file in the project A source code, I get the error which tell me I am using a undefined class like this "d:\microsoft visual studio\vc98\mfc\include\afxtempl.h(1112) : error C2079: '$S226' uses undefined class '$S226' ... " 

----- problem -----

   what is this problem ? can somebody kindly help me to solve ? My environment is NT4.0, VC++6.0. thank you very much in advance.


-- pigangel
   
Avatar of migel
migel

Hi!
check your project settings ('A') it must contain path to the lib header files.
also make shure that these files has no conflict with guard defines.
Guard defines usually looks like this (in the header files)

//start *.h file
#ifndef __MYFILE_H__
#define __MYFILE_H__ 1
// rest of file
// and at the end
#endif //__MYFILE_H__

also you can determine what happens by compile *.cpp file with /P option (sets manually for file (or entire project)in the project  options dialog|compiler tab  in the compiler switches edit box at the page botom).
you get *.i file where preprocessor dumps results.
In this file you can see what include files really included in the build.
Avatar of pigangel

ASKER

Hi,migel:
  how should I check if the files has confiict with guard defines? I know these guard defines normally are auto-created when create a new class.

-- pigangel
Hi,
Actually, /P option is already on for the whole project, but I cann't find out *.i files, where can I get it?

-- pigangel
Hi!
to get *.i file you must compile file where you get error.
Avatar of DanRollins
This can happen when VC++ erroneously thinks that it does not need to recompile the precompiled header.  If that is the problem, one solution is to clean and rebuild:

Right-click each project (A, B, and the free one) and select "Clean."  Then again right-click each project and choose "Build."

If that doesn't work, you must examine *all* of the settings for the project that works, and compare them to those of the project that fails.  This is possible using the  Project Settings dialog.  

Open that dialog and select "Project A" (the one that works)  Now cycle through each items in the combobox on the C/C++ and Link tabs.  Select the category then click on "Project B" and then back on "Project A" several times.  Any differences will be easy to spot.  

Tip: If you fix something in the Debug build settings, you will also want to fix it in the Release build.

-- Dan
Hi, Dan:
  I had tried clean and build again, but it doesn't work. I am trying to compare the project setting, will let you know the result. but my question is why VC++ sometime erroneously think that it does not need to recomplile the precompiled header?

--pigangel
>>BUT I can not see those Header files inside free project in External dependences list of my project

If you add the .h of the Library then it will not appear in the External Dependencies list.

>>why VC++ sometime erroneously think that it does not
need to recomplile the precompiled header?

I have a theory:  I think that VC++ makes a special case for resource.h -- when modified by the ClassWizard.  Otherwise, many simple tweeks would force a rebuild of nearly every module.  You can see this in action.  If you have two CDialog-based classes (A and B), then add a new edit box (IDD_EDIT1) to dlg A, then when you rebuild the project, dlg B does not get rebuilt -- even though resource.h has clearly been modified.

That does not explain all situations, but it is enough of a clue -- if there is "special case" logic going on in one place, I'd not be surprised to see it taking place (and getting messed up) in other situations.
Hi,Dan:
  The project setting is same, so I am getting more and more confused.
  even I did like following:
  1) Add the free.lib with the proper path eg. ..\free\debug\free.lb to project setting->Link->Input->Object/library modles.
  2) Add the free library directory eg ..\free to project setting->C++->Preprocessor->Additional include directories.

  I still get the same error, it seems the my project will never see the header file and never like to free lib. what happened in my project!

Hi, migel:
  sorry,I had misunderstood the /P option you mentioned! can you please tell me how to set this option manually? thanks.



-- pigangel
Hi!
press ALT+F7 on the project
select C/C++ tab look at page bottom and in the "Project option" set caret at the strings end and type /P
>>my project will never see the header file

Right-click on the project and choose Add Files to Project.  Then drill-down and locate the .H file (c:\somedir\free\free.h)

-- Dan
hi pigangel,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
Hello, Dan:
  I am sorry I had tried to solve another problem (please see my new posted question) after I showed my project to my client).
  I will try your latest suggestion tonight and will tell you the result.
  thank you!

-- pigangel
Hi Dan. I tried to add those header files into my project,and I still got the same error, I totally have no idea about my project!

--pigangel
Hi!
can you send me your workspace Or tell me what free lib you use to emulate your problem on my compute?
my Email is: migel.geo@yahoo.com
Look at the project that works and look at a file that uses the line

#include "free.h"

Now look just above that #include line.  There may be other #include files that you are forgeting to put into your broken project.  

Also compare the file named stdafx.h for both projects.

-- Dan
Hi, migel:
  I tried the /P option and built the project again,
Actually in my class BackupDlg.cpp file, I included the header file of the free project which build a free LIB ( not DLL ), I look into the BackupDlg.i file, and I found that the include header file was included in project-build like following( am I right?):

--
#line 8 "d:\\src2\\backupdlg.cpp"
#line 1 "d:\\free\\free.h"
...
---

if the header file is included like this but my project still can't see it, do you think this is becasue  that the header file has conflict with guard defines? are there any ways for me to check if it has conflict with guard defines or not. please kindly give me any hints. thanks a lot.

-- pigangel  

Hi!
in the *.i file you must see all declarations existing in the d:\\free\\free.h
that is something like this:
#line 1 ":\\free\\free.h"

class FreeClass //and so on
{
};
...
//..rest of file
...

#line 9 "d:\\src2\\backupdlg.cpp"
if you see empty space the you have guards conflict
search where this quard can be defined in the all project files.
Hello, migel & Dan:
  thank you very much for all your support! it's right like Dan had said, need to check the header files eg stdafx.h ...  and migel helped me to find out the place!!
  migel can you please tell me why I should include <afxtmpl.h>, for me I only know if I use some template e.g CList, I need to include it... by the way what is IMHO means?
  Thanks again, I will accept migel's as answer.


-- pigangel with (^_^)
ASKER CERTIFIED SOLUTION
Avatar of migel
migel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much!

-- pigangel