Author Topic: Can CB use a linux shell script to build a project?  (Read 8416 times)

Offline Marnix

  • Multiple posting newcomer
  • *
  • Posts: 19
Can CB use a linux shell script to build a project?
« on: June 02, 2018, 01:40:48 pm »
I use CB on linux mint.

I have a C/C++ project that I must build from the command line, by running a shell script.

This is what the script looks like (I removed .c and .o filenames)

====================================================
OPT="-g -I../common -I../ifi -DIFI_BUILD -DLOG_MT -DLOGGING"

# xvan c-files
XVAN="<file list removed>"

# xvan o-files
XVANO=”<file list removed>"

# compile the C files
gcc -c -fPIC $OPT $XVAN

# compile the C++ and link into shared lib (linux)
g++ -fPIC -shared -o ifigame.so -std=c++11 $OPT ifixvan.cpp ../ifi/ifiglue.cpp $XVANO

# compile console front end, link with shared lib (linux)
g++ -std=c++11 $OPT -DIFI_IMPORT -o ificonsole ../ifi/ificonsole.cpp -L. -l:ifigame.so -pthread
====================================================

I want to build the project in CB so I can debug it.

Is there a way I can tell CB to use the .sh file to build the project? Or, alternatively, do we have instructions how to "translate" a .sh to CB build settings?

I hope someone can answer this.

Offline sodev

  • Regular
  • ***
  • Posts: 496
Re: Can CB use a linux shell script to build a project?
« Reply #1 on: June 02, 2018, 04:15:57 pm »
I have seen a lot of shit, but this is the first time that i see someone building code on linux with a shell script ;D. Use a Makefile to build your code, shouldn't be that hard to turn your script into one because it is already closely structured like one.

Then you can create a CodeBlocks project that uses an external Makefile, however certain things don't work in CodeBlocks then, i don't know how much debugging is affected.

If u just need to track a crash, you could also run your application directly under gdb in a shell ;)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can CB use a linux shell script to build a project?
« Reply #2 on: June 02, 2018, 05:45:57 pm »
I have seen a lot of shit, but this is the first time that i see someone building code on linux with a shell script ;D.
It will be good if you can start to watch your language a bit.
Shell scripting is pretty common when people doesn't bother to learn make syntax or just want to hack something fast.

Then you can create a CodeBlocks project that uses an external Makefile, however certain things don't work in CodeBlocks then, i don't know how much debugging is affected.
@Marnix: The above is true even for your shell script. But you have to change the makefile executables to match your settings. But if this is the full shell script it would be a lot easier if you create a cb project. I don't see anything that the UI can't do.

Also you can always attach to your executable if it is waiting for user input as last resort.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Marnix

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Can CB use a linux shell script to build a project?
« Reply #3 on: June 03, 2018, 04:43:00 pm »
....... But if this is the full shell script it would be a lot easier if you create a cb project. I don't see anything that the UI can't do.......

Yes I would prefer a CB project, but don't know how to translate the shell script to CB settings. I've used CB for a quite some time, but my applications always were c-files and header files.

From this script, someone gave it to me, I see that:
- first, it compiles the c-files to object files;
- next, it creates a .so file from the object files and some other files.
- finaly, it creates the application with the .so file and a cpp file.

Can this all be done in 1 CB project?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can CB use a linux shell script to build a project?
« Reply #4 on: June 03, 2018, 06:44:13 pm »
Yes, it can. The projects used to build C::B are like this.

The idea is:
1. create two targets
2. name them library and application
3. make sure library is above application
4. make a virtual target to group both targets
5. build the virtual target (it will build its targets from top to bottom)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Marnix

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Can CB use a linux shell script to build a project?
« Reply #5 on: June 17, 2018, 01:42:02 pm »
Well, i've studied the manual about build targets, but I have had no success in converting the shell script to CB build targets. I hope someone can help me out.

The first build target must create the ifigame.so library. I figured out the build target must be of type dynamic library.  But I have no clue what to enter for import library filename and Definition file filename. And the build target file selection pane is greyed out so I cannot select files. I'm sure it must be pretty basic but I just don know how to proceed.

There are 2 build targets, debug and release (console applications) that were created when I started the project. I tried to analyze these to get an idea how build targets work, but they seem identical but for the file name. So, now I'm even more confused.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can CB use a linux shell script to build a project?
« Reply #6 on: June 17, 2018, 05:53:42 pm »
The first build target must create the ifigame.so library. I figured out the build target must be of type dynamic library.  But I have no clue what to enter for import library filename and Definition file filename. And the build target file selection pane is greyed out so I cannot select files. I'm sure it must be pretty basic but I just don know how to proceed.
Ignore these. They are for windows.

There are 2 build targets, debug and release (console applications) that were created when I started the project. I tried to analyze these to get an idea how build targets work, but they seem identical but for the file name. So, now I'm even more confused.
If you compare the build options related to the compiler of the two you'll see that the release target has full optimizations enabled and the debug target has the debugging options enabled.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Marnix

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Can CB use a linux shell script to build a project?
« Reply #7 on: June 18, 2018, 10:17:27 pm »
Well, I did as you told and I got it to work! I now got 1 virtual target that consists of a library and an application. It was a bit of a puzzle, though. E.g. the '-pthread' should go to the 'other linker options' in the linker settings tab and not to the 'other options' in the compiler settings.

Thanks a lot for your help in getting this up and running!

So, from the command line, the application starts with: ./ificonsole -d 3 -configdir escape -story escape.dat

Does that mean i must copy "-d 3 -configdir escape -story escape.dat" to the program argument's window and select the target that is the application as the main executable? I cannot find a thing about it in the manual.

And what do "host application" and "run host in terminal mean" in the program arguments window?


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can CB use a linux shell script to build a project?
« Reply #8 on: June 19, 2018, 12:24:33 am »
It was a bit of a puzzle, though. E.g. the '-pthread' should go to the 'other linker options' in the linker settings tab and not to the 'other options' in the compiler settings.
If you read the manual of gcc you'll find that it must go in both places.


Does that mean i must copy "-d 3 -configdir escape -story escape.dat" to the program argument's window and select the target that is the application as the main executable?
Yes, this is how it is supposed to be done.

And what do "host application" and "run host in terminal mean" in the program arguments window?
This is used when you have only a library project and the application is some external application. There you place the path to the application's executable.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Marnix

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Can CB use a linux shell script to build a project?
« Reply #9 on: June 21, 2018, 09:03:54 pm »
I noticed that when I

3. make sure library is above application

and then build the virtual project, CB

- cleans the application
- cleans the library
- starts building the application
- and throws an error about not being able to find the library (which makes sense, because it just cleaned it)

When I put the application above the library, the library is built first and all goes ok. It looks like it builds from bottom to top?


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can CB use a linux shell script to build a project?
« Reply #10 on: June 21, 2018, 11:35:32 pm »
In which dialog are you setting the order?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Marnix

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Can CB use a linux shell script to build a project?
« Reply #11 on: June 22, 2018, 07:59:06 am »
project -> properties -> tab 'build targets' -> button 're-order'

I'm on version 13.12

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can CB use a linux shell script to build a project?
« Reply #12 on: June 22, 2018, 08:55:18 am »
The codeblocks projects use this technique and the order is from top to bottom.
I doubt we changed this since 13.12, but who knows.
It is best to try the latest version.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline sodev

  • Regular
  • ***
  • Posts: 496
Re: Can CB use a linux shell script to build a project?
« Reply #13 on: June 22, 2018, 09:28:39 am »
Why so complicated? I am doing multi-project builds with CodeBlocks for many years now, i never needed virtual targets or sort anything, build order is determined automatically by project dependencies.

(Granted, i currently don't remember how to define these and in some dark days in the past that didnt work and i had to mess around with external dependencies. But i removed these hacks a long time ago from my modified PreMake that generates the CodeBlocks project files for me for many years now :) )

Offline Marnix

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Can CB use a linux shell script to build a project?
« Reply #14 on: June 22, 2018, 12:20:37 pm »
I believe my situation is different. I only have 1 project in which I build a library and an application. The linker needs the library for the application, so the library must be build before the application.

I don't have multiple projects with dependencies.

Anyway, it's not a big deal. I can build the project by listing the application build target first. I just wondered why it didn't work like oBFusCATed said.

I think I'll upgrade to the latest version and see what happens then.