NO

Author Topic: Integration of several compilation units  (Read 3737 times)

Offline sgraffe

  • Member
  • *
  • Posts: 20
Integration of several compilation units
« on: September 06, 2017, 12:25:42 AM »
Hello, all:

I wan to integrate several compilation units from different projects, so common functionality can be shared. I have tried the following:

I created projectA with:
1. source code unit1.c, referring to include file unit1.h
2. source code unit2.c, referring to include files unit2.h and unit1.h (unit2 uses fun1a() and fun1b() from unit1)
3. main.c, referring to include file unit2.h
It compiled and built OK.

I then created projectB with source code unit1.c  and include file unit1.h
unit1.c and unit1.h were detached from projectA and moved to new folder.

Unit2 in projectA now refers to new  include file location: "\newdir\unit1.h"

projectA  and projectB compile ok, but when building projectA, I get unresolved externals _fun1a and _fun1b .

I tried adding projectB to the workspace of projectA but nothing happened. Also tried to include the output folder of projectB in the library folder options of projectA. I imagine obj files are not libraries.

How can I integrate projectA into project B, so functions from unit1 can be resolved from projectB?

Regards,
Simon

Jokaste

  • Guest
Re: Integration of several compilation units
« Reply #1 on: September 07, 2017, 08:33:25 AM »
This kind of project is when we create a DLL.
Into your workspace you must have Project2 then Project1 (respect the order)
You must have a include file, in project1, that describes the functions in Project2
Project2 must be a library
For the linker, add Project2.lib into the libaries : Tab Linker, Libary and Project Files

Offline sgraffe

  • Member
  • *
  • Posts: 20
Re: Integration of several compilation units
« Reply #2 on: September 07, 2017, 04:07:24 PM »
Thanks Jokaste:

A DLL is very complicated for my experience level. I just want to share code, not binaries, and separated my project into units unit1.c, unit2.c, etc. with respective unit1.h, unit2.h...

New projects can use unit1.obj, unit2.obj etc.
The solution I have come to now is the following:

Moved all include files to a common folder.
Added that folder to the new projects in "Project Options / Folders / Includes"
Added all unit1.obj... to the new project in "Project Options / Linker / Library and object files"

And it works, but it is somewhat cumbersome.
First, now the include files of each unit have to be located in a folder different than the unit folder. Then, I have to add all the filenames in one line for the linker, incuding the full path in each project that uses them. And sometimes the Pelles IDE misbehaves when some project files are deleted from the operating system. I have had to recreate some projects.

The ideal solution (and I thought it was, please correct me if I am wrong) would be to add the projects to the workspace, and automatically have available the obj and include files from the othe projects.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Integration of several compilation units
« Reply #3 on: September 07, 2017, 05:30:55 PM »
Use library for shared objects or just include sources.
Small example of two projects in workspace.
May the source be with you

Offline sgraffe

  • Member
  • *
  • Posts: 20
Re: Integration of several compilation units
« Reply #4 on: September 08, 2017, 04:25:58 AM »
Thank you very much, Timo, for taking your time to develop an example:

I tried to recreate your workspace structure.

Initially I created a project and added two more projects to the workspace. But then I couldn't add files from one project to the other, because they have to be under the directory the project is in.

So to mimic your directory structure, I did the following (I attached the resultant files, just stubs, to this message):

1. Created a project in directory newLib
2. Created project BagInt (no files added) in directory BagInt under newLib
3. Created project mainBag (no files added) in director mainBag under the same directory newLib
4. Moved BagInt.ppj, .ppx up one level from directory Bagint to directory new Lib
5. Did the same to mainBag from directory mainBag
6. Added files to each project. BagInt.c compiles ok.
7. Opened project newLib.ppj and added projects BagInt.ppj and mainBag.ppj to the workspace. newLib.ppw was created, so I deleted newLib.ppj
8. Now I can open newLibb.ppw, and add BagInt.c to mainBag.exe. Automatically BagInt.h appears under include files in mainBag.exe. Looks very good.

So far, it is very similar to your example, but when I compile main.c, I get fatal error #1035: Can't find include file "BagInt.h", even though it appears under include files in mainBag.exe.

Any idea what I am missing?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Integration of several compilation units
« Reply #5 on: September 08, 2017, 09:31:05 AM »
Insert include path of BagInt to mainBag project for main.c

An example using static lib.
« Last Edit: September 08, 2017, 09:45:32 AM by TimoVJL »
May the source be with you

Offline sgraffe

  • Member
  • *
  • Posts: 20
Re: Integration of several compilation units
« Reply #6 on: September 08, 2017, 05:11:55 PM »
Yes, it works, I hadn't noticed it before in your example, but the IDE knows where the include file is because it shows the include under the mainBag project, so I think I shouldn't have to tell it where to look.

I added the test drivers, and there is a gotcha. All obj files are saved in a common directory, so test modules cannot have the same name (test.c, or main.c for example). Just a minor inconvenience. Rebuilding kills the problem, but it is better to have a different name for each test (testUnit1.c, f.e.), so you can build or rebuild.

Thank you very much for the new example. I am going to look into it.

Best regards,

Offline sgraffe

  • Member
  • *
  • Posts: 20
Re: Integration of several compilation units
« Reply #7 on: September 09, 2017, 06:49:01 AM »
I recreated your example of library. I like this approach. At the beginning it didn't work, I got unresolved externals, that was caused by different calling conventions which I fixed. Thank you for the example, I learned a lot.

One last question: How do you change the output dir of the compiler from "output" to "out32" like your example, or any other dir? I would like to compile each unit test driver to a separate directory.

Best regards,


Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Integration of several compilation units
« Reply #8 on: September 09, 2017, 10:15:56 AM »
Just manually edit .ppj file:
POC_PROJECT_OUTPUTDIR = output#
and where that output is used.

out32 ?
http://forum.pellesc.de/index.php?topic=4603.msg21270#msg21270

WSEdit (from L.D.Blake):
http://www.johnfindlay.plus.com/pellesc/addin/addin.html
http://www.johnfindlay.plus.com/pellesc/addin/Addins.zip
« Last Edit: September 09, 2017, 10:31:03 AM by TimoVJL »
May the source be with you

Offline sgraffe

  • Member
  • *
  • Posts: 20
Re: Integration of several compilation units
« Reply #9 on: September 09, 2017, 05:42:32 PM »
Thank you very much!

Best regards,