Author Topic: multiple file c++ project  (Read 11342 times)

Offline Robert_S

  • Multiple posting newcomer
  • *
  • Posts: 11
multiple file c++ project
« on: September 03, 2007, 10:40:48 pm »
Hi, I have just installed CodeBlocks 10. rc2 and the most recent build of MinGW. They are installed and runing as expected.

Please bear with me as I am compltely new to both these programs and I'm trying to familiarise myself with using them.
I have been trying to compile a multifile open source project with no success as yet.

I created a new console project, checked the "don't create an file box" and then added files recursively to the the workspace.
This creates Source and Header folders as expected.  The trouble I have is if I select the .cc file which contains main and attemp to compile it I get a build error error message stating that it cannot find a particular header file which is contained and one of the project subfolders.

I've searched the forum and don't seem to be able to find an answer to this.  Can anone tell me how to fix it please?
Or better still could they attempt to build the program and give me a guide on how to achieve this.

The source code can be found here:
                                                ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.02.tar.gz

I'm trying to build pdfinfo.cc.
   

Offline Robert_S

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: multiple file c++ project
« Reply #1 on: September 03, 2007, 11:08:27 pm »
update.  Okay I've found that I should have all the source files in one common folder.
CB still can't seemto find a particular header file that is present in that folder.
Any ideas?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: multiple file c++ project
« Reply #2 on: September 03, 2007, 11:09:37 pm »
well apart from the problem you might have, I would like to suggest to use an nightly build. RC2 is so old ;-)

Offline Robert_S

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: multiple file c++ project
« Reply #3 on: September 03, 2007, 11:57:23 pm »
Okay I'll try a nightly build as you suggest.  The file header file that is report missing is aconf.h, if you right click and select open #include file 'aconf.h' C::B will display it without error.

I looked at the ms_make.bat for some clues and it has the line : copy aconf-win32.h aconf.h
I just renamed aconf-win32.h to aconf.h.  The error remains the same.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: multiple file c++ project
« Reply #4 on: September 04, 2007, 10:15:42 am »
Hmm... I don't have that header on my system, so I guess it belongs to the package you want to compile. In this case, you probably want to add the folder that contains all the project's includes to the compiler's search path.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Robert_S

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: multiple file c++ project
« Reply #5 on: September 04, 2007, 10:26:57 am »
Hmm... I don't have that header on my system, so I guess it belongs to the package you want to compile. In this case, you probably want to add the folder that contains all the project's includes to the compiler's search path.

That's correct the header is part of the package and is present in the source folder.  How do I add the include in the compilers search path?  Is that Settings->Global Variables and then enter folder path in the include field?  I've just  tried this to no avail.

UPDATE: I uninstalled rc2 as suggested and installed and configured the latest nightly build.  I still get the error message "aconf.h: No such file or directory"  I hope that somebody can steer me in the right direction.
I'd be very grateful. At this stage my aim is to have an IDE that I am comfortable with using and be able to compile this project and have a play with it to learn how it works.

I hope that somebody can steer me in the right direction.

Thankyou,
              Robert.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: multiple file c++ project
« Reply #6 on: September 04, 2007, 11:22:03 am »
I've had a look at this package now, and I don't think you will be able to easily compile it, if you're a beginner.
First of all, it has a terrible project layout, you need to add a couple of search paths, and you have to sort out files that don't belong into your project. Also, you must rename aconf-win32.h as you have already done.

Half of the package depends on additional packages (which you probably don't have) or on X11 specific stuff, so you can't just compile everything. You have to look at the ms_make.bat and only add the files that are listed there, and you have to sort them into individual targets.

I have attached a project file that does most of this and compiles about half of it (the goo, fofi, and splash libs) successfully. Not knowing what the xpdf software looks like, I've put the rest into one target, which of course fails with "multiple definitions of main()" as there are 4-5 subprograms in it, actually.
You will have to put pdfopts.cc, pdfinfo.cc, pdffonts.cc, and pdfimages.cc into separate targets, creating separate programs. Still a lot of work, but you get the idea... duplicate the xpdf target 4 times, change the output filename accordingly, and make sure only one of the forementioned sources is checked for each target. Maybe using the attached project is nevertheless helpful.
Also, at the very end, it complains about something missing... but I have given up :)

[attachment deleted by admin]
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: multiple file c++ project
« Reply #7 on: September 04, 2007, 11:49:28 am »
Oh, I forgot... you must add goo and fofi (and possibly splash) to the link libraries for the targets that build the 4-5 executables, else you will get missing references.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Robert_S

  • Multiple posting newcomer
  • *
  • Posts: 11
getting closer...
« Reply #8 on: September 04, 2007, 01:02:36 pm »
Please accept my apologies I've created a new thread by accident can a moderator move this to my original thread please?  Thanks for your patience.

I've had a look at this package now, and I don't think you will be able to easily compile it, if you're a beginner.
First of all, it has a terrible project layout, you need to add a couple of search paths, and you have to sort out files that don't belong into your project. Also, you must rename aconf-win32.h as you have already done.
Hi Thomas thankyou for taking the time to look at this.  I now know to add the seach paths with the global compiler settings, previously I had copied all files to a single folder.

Half of the package depends on additional packages (which you probably don't have) or on X11 specific stuff, so you can't just compile everything. You have to look at the ms_make.bat and only add the files that are listed there, and you have to sort them into individual targets.
The X11 specific stuff is only for only for xpdf itself and for running under XWindows.  I used the mas_make.bat file as a guide to what files I need to add to the project workspace.


I have attached a project file that does most of this and compiles about half of it (the goo, fofi, and splash libs) successfully. Not knowing what the xpdf software looks like, I've put the rest into one target, which of course fails with "multiple definitions of main()" as there are 4-5 subprograms in it, actually.
You will have to put pdfopts.cc, pdfinfo.cc, pdffonts.cc, and pdfimages.cc into separate targets, creating separate programs. Still a lot of work, but you get the idea... duplicate the xpdf target 4 times, change the output filename accordingly, and make sure only one of the forementioned sources is checked for each target. Maybe using the attached project is nevertheless helpful.
Also, at the very end, it complains about something missing... but I have given up :)
I'm only looking to compile pdfinfo.cc, sorry I should have mentioned this from the outset.  If I

Half of the package depends on additional packages (which you probably don't have) or on X11 specific stuff, so you can't just compile everything. You have to look at the ms_make.bat and only add the files that are listed there, and you have to sort them into individual targets.

I have attached a project file that does most of this and compiles about half of it (the goo, fofi, and splash libs) successfully. Not knowing what the xpdf software looks like, I've put the rest into one target, which of course fails with "multiple definitions of main()" as there are 4-5 subprograms in it, actually.
You will have to put pdfopts.cc, pdfinfo.cc, pdffonts.cc, and pdfimages.cc into separate targets, creating separate programs. Still a lot of work, but you get the idea... duplicate the xpdf target 4 times, change the output filename accordingly, and make sure only one of the forementioned sources is checked for each target. Maybe using the attached project is nevertheless helpful.
Also, at the very end, it complains about something missing... but I have given up :)

I've nearly got it to compile now now thanks to your help.  The only error I get now is:

-------------- Build: Debug in pdfinfo ---------------
Compiling: ..\gmempp.cc
Linking console executable: bin\Debug\pdfinfo.exe
obj\Debug\GlobalParams.o: In function `ZN11WinFontListC2EPc':C:/xpdf-3.02/xpdf/GlobalParams.cc:284: undefined reference to `EnumFontsA@16'
obj\Debug\GlobalParams.o: In function `ZN11WinFontListC1EPc':C:/xpdf-3.02/xpdf/GlobalParams.cc:284: undefined reference to `EnumFontsA@16'
obj\Debug\GlobalParams.o: In function `ZN11WinFontList9enumFunc1EPK11tagLOGFONTAPK14tagTEXTMETRICAml':C:/xpdf-3.02/xpdf/GlobalParams.cc:382: undefined reference to `EnumFontsA@16'
obj\Debug\pdfinfo.o: In function `ZN6Object9getStringEv':C:/xpdf-3.02/xpdf//GString.h:(.text+0xa3): undefined reference to `parseArgs'
:C:/xpdf-3.02/xpdf//GString.h:(.text+0x13f): undefined reference to `printUsage'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings

I'm really not sure how to proceed from here.  Can you or anyone help please?
« Last Edit: September 04, 2007, 01:11:45 pm by Robert_S »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: multiple file c++ project
« Reply #9 on: September 04, 2007, 01:19:03 pm »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: multiple file c++ project
« Reply #10 on: September 04, 2007, 01:31:31 pm »
Add gdi32 to link libraries.
Right. BTW: Ths project contains a lot of executables that could be producers (I'm sure you realised the "multiple main" error). I have attached a slightly modified project for all the executables. Still: Some of them I have disabled int he virtual target "All" as they are depend on components I don't have. ;-)

[attachment deleted by admin]
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Robert_S

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: multiple file c++ project
« Reply #11 on: September 04, 2007, 01:52:04 pm »
Add gdi32 to link libraries.

http://msdn2.microsoft.com/en-us/library/ms533964.aspx

I placed a copy of gdi32.lib into C:\MinGW\lib, I used a copy from an old vc98 installation as I do not have MSDN.  I still receive the aforemetioned errors.  I also pointed to it within the Global Variable editor.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: multiple file c++ project
« Reply #12 on: September 04, 2007, 02:25:38 pm »
GCC (MinGW) can't link your app against a VC compiled lib. You need to download the following package instead.

Quote
http://downloads.sourceforge.net/mingw/w32api-3.10.tar.gz?modtime=1186139469&big_mirror=1
Be a part of the solution, not a part of the problem.

Offline Robert_S

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: multiple file c++ project
« Reply #13 on: September 04, 2007, 02:41:10 pm »
GCC (MinGW) can't link your app against a VC compiled lib. You need to download the following package instead.

Quote
http://downloads.sourceforge.net/mingw/w32api-3.10.tar.gz?modtime=1186139469&big_mirror=1

Hmmm  not sure I how I would go about using the win32api archive you quote.  How would I use this?

I managed to get gdi32.lib to link by using Settings->Complier and Debugger-> selcting the linker settings Tab and pointing to gdi32.lib.

Now I get the following build log displayed...
-------------- Build: Debug in pdfinfo ---------------
Linking console executable: bin\Debug\pdfinfo.exe
obj\Debug\pdfinfo.o: In function `ZN6Object9getStringEv':C:/xpdf-3.02/xpdf//GString.h:(.text+0xa3): undefined reference to `parseArgs'
:C:/xpdf-3.02/xpdf//GString.h:(.text+0x13f): undefined reference to `printUsage
'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings

Looking at the Gstring.h header, what does the reference to (.text+0x13f) refer to ? I can't see any reference to `printUsage'.
Just one last hurdle to overcome and hopefully I'll have a working binary.  Thanks for all the input and assistance thus far :).

Could it be something to do with the following (taken from MS_MAKE.BAT):


GHash.cc,  GList.cc, GString.cc, gmem.cc, gmempp.cc, gfile.cc, parseargs.c
Needing to be compiled as objects file and output as Goo.lib ?

and...

FoFiBase.cc, FoFiEncodings.cc, FoFiTrueType.cc,  FoFiType1.cc,  FoFiType1C.cc
Needing to be compiled as object files and output as fofi.lib ?

How do I produce library files to link in?

update:
Looking at the ms_make.bat file again I see I also need to link shell32.lib ,user32.lib,  advapi32.lib.  So I'll add these and see how I progress.
I've noticed MinGW\lib has the following libraries: libshell32.a ,libuser32.a,  libadvapi32.a but no libgdi32.a there or in the linked above.  Is there an alternative library or something to use?
« Last Edit: September 04, 2007, 04:14:35 pm by Robert_S »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: multiple file c++ project
« Reply #14 on: September 04, 2007, 03:52:52 pm »
Quote
GHash.cc,  GList.cc, GString.cc, gmem.cc, gmempp.cc, gfile.cc, parseargs.c
Needing to be compiled as objects file and output as Goo.lib ?

and...

FoFiBase.cc, FoFiEncodings.cc, FoFiTrueType.cc,  FoFiType1.cc,  FoFiType1C.cc
Needing to be compiled as object files and output as fofi.lib ?

How do I produce library files to link in?
Look in the attached project, it does just that. The target goo builds the library libgoo.a, placed into the folder lib, etc.


Oh, I forgot... you must add goo and fofi (and possibly splash) to the link libraries for the targets that build the 4-5 executables, else you will get missing references.
You really need to do that, too :)

If you add the lib folder to the linker's search paths (which is the good solution), you can just add goo, fofi, and splash to link libraries.
Alternatively, you can provide absolute paths or copy the libraries to the system lib folder (both aren't good solutions, though).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."