Shop OBEX P1 Docs P2 Docs Learn Events
SimpleIDE "Project Libraries" question — Parallax Forums

SimpleIDE "Project Libraries" question

DavidZemonDavidZemon Posts: 2,973
edited 2017-02-20 16:29 in Learn with BlocklyProp
I have a question about how SimpleIDE deals with "project libraries". I'm thrilled to see that new version of the Simple-Libraries source code have SimpleIDE project files (.side files) for every library, because I can now provide compiled versions of these libraries with PropWare with a higher level of confidence that they are compatible with the versions provided by SimpleIDE. I get this confidence by parsing the SimpleIDE project files in PropWare's build system and using that to build the libraries, rather than searching for all .c files and then adding a bunch of exceptions and extra rules to try and find the correct files (and now I can use the compilation flags provided by the .side files! even better).

But I ran into a snag: most, if not all, of the project files list a source file with a main function in it. When I open one of these project files in SimpleIDE and click the "Build" button, SimpleIDE is smart enough to ignore that file with the main definition. How does it know to do that? Does it always exclude the first line in the project file? That seems a bit unlikely to me because that would mean SimpleIDE is incapable of having a library-only project, which I didn't think was the case. Is SimpleIDE opening every file and looking for a definition of main, and then excluding any file(s) that have such a definition?

Here's one such project file
libcolormath.c
colormath.h
compareRRGGBB.c
get8bitColor.c
getColorRRGGBB.c
remapColor.c
>compiler=C
>memtype=cmm main ram compact
>optimize=-Os
>-m32bit-doubles
>-fno-exceptions
>defs::-std=c99
>-lm
>-create_library
>BOARD::ACTIVITYBOARD

And here's the output when clicking the "Build" button:
Project Directory: /......./PropellerProjects/PropWare/Simple-Libraries/Learn/Simple Libraries/Utility/libcolormath/

SimpleIDE Version 1.1.0
/home/david/Documents/SimpleIDE/Learn/Simple Libraries/
/home/david/Documents/SimpleIDE/ Updated on: 2017-02-20

propeller-elf-gcc -v GCC 4.6.1 (propellergcc-alpha_v1_9_0_)
propeller-elf-gcc -I . -L . -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 -c compareRRGGBB.c -o cmm/compareRRGGBB.o
propeller-elf-gcc -I . -L . -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 -c get8bitColor.c -o cmm/get8bitColor.o
propeller-elf-gcc -I . -L . -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 -c getColorRRGGBB.c -o cmm/getColorRRGGBB.o
propeller-elf-gcc -I . -L . -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 -c remapColor.c -o cmm/remapColor.o
propeller-elf-ar rs cmm/libcolormath.a cmm/compareRRGGBB.o cmm/get8bitColor.o cmm/getColorRRGGBB.o cmm/remapColor.o
/opt/parallax/bin/propeller-elf-ar: creating cmm/libcolormath.a
propeller-elf-gcc -I . -L . -o libcolormath.elf -Os -mcmm -m32bit-doubles -fno-exceptions -std=c99 libcolormath.c cmm/libcolormath.a -lm
propeller-load -s libcolormath.elf
propeller-elf-objdump -h libcolormath.elf
Done. Build Succeeded!

Notice that libcolormath.o is magically excluded from the invocation of propeller-elf-ar

Comments

  • Hi David,

    Good, I'm glad to hear that having a .side file for each project helps.

    This line inside the .side file:

    >-create_library

    ...gets added when a user opens SimpleIDE's project manager, clicks the Linker tab, and then clicks the Create Project Library checkbox.

    Andy
  • Hi David,

    Good, I'm glad to hear that having a .side file for each project helps.

    This line inside the .side file:

    >-create_library

    ...gets added when a user opens SimpleIDE's project manager, clicks the Linker tab, and then clicks the Create Project Library checkbox.

    Andy

    Yes, I found that line and it's very helpful. But how does SimpleIDE know not to add files with a main() function to the library?
  • DavidZemon wrote: »
    SimpleIDE is smart enough to ignore that file with the main definition. How does it know to do that? Does it always exclude the first line in the project file?

    It excludes the first file in the project. What you are looking for is in propside/buildc.cpp:
            /* Run through file list and compile according to extension.
             * Add main file after going through the list. i.e start at list[1]
             */
            QStringList inclist;
            for(int n = 1; rc == 0 && n < list.length(); n++) {
    

    There is other "magic" used to detect the libraries based on the #include statements.
  • Perfect! Thank you. That is an algorithm I can replicate! :D
Sign In or Register to comment.