Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Marnix on June 02, 2018, 01:40:48 pm

Title: Can CB use a linux shell script to build a project?
Post by: Marnix 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.
Title: Re: Can CB use a linux shell script to build a project?
Post by: sodev 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 ;)
Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed 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.
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix 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?
Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed 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)
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix 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.
Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed 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.
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix 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?

Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed 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.
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix 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?

Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed on June 21, 2018, 11:35:32 pm
In which dialog are you setting the order?
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix on June 22, 2018, 07:59:06 am
project -> properties -> tab 'build targets' -> button 're-order'

I'm on version 13.12
Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed 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.
Title: Re: Can CB use a linux shell script to build a project?
Post by: sodev 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 :) )
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix 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.
Title: Re: Can CB use a linux shell script to build a project?
Post by: sodev on June 22, 2018, 01:10:04 pm
This happens when you don't read the full thread ;D.

You are using the targets for something different than i and the CodeBlocks wizards and documentation do! We use them to build different configurations of the same thing while you use them to build different things.

Since i never used your path i cant contribute anything to it and i don't want to confuse you with mine so i better stop here :). Just a little strange that oBFusCATed suggets a path contradicting the integrated helper functions to a beginner.
Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed on June 22, 2018, 06:43:53 pm
sodev: What do you mean by integrated helper functions? The wizard scripts?
Title: Re: Can CB use a linux shell script to build a project?
Post by: sodev on June 22, 2018, 09:15:13 pm
Yes, these, and to some extent the wiki as well.
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix on June 27, 2018, 09:15:50 pm
== long post, but oBFusCATed pls read  :) ==

Ok, I can now build the library and the application in one project and it runs as it should. But now, I have this weird problem with the debugger.

Here’s the problem and results of the testing I already did:

Problem: when I start the debugger the terminal window does not start

My own testing:
1. Upgraded to CB 17.12
2. The project builds the library and the application without errors
3. The application runs fine outside CB
4. The application runs fine from within CB using “run” (CTRL F10). The terminal window starts, prints output and accepts input.
5. When I start the application in the debugger with “start/continue” (F8), it looks like it gets into a loop. I think it's waiting for input that doesn't come because of the missing terminal window. Only the “stop debugger” and “break debugger” buttons are clickable but they don seem to work.
6. Clicking “stop debugger” or “break debugger” gives the following msg in the debugger window:
“Trying to interrupt process with pid: 7349; child pid: 7349 gdb pid: 7343”.
When I kill -9 the last pid, the debugger stops.
5. When I start the application in the debugger with “run to cursor” (F4) to a point where no user input is yet required, I can F7 through it, but there is no terminal window.
6. My other projects that only build an application and no library run fine in debug mode, the terminal window starts normally.

Because everything else works, but for the debugger in this particular project that builds a library and an application I think I missed a correct setting somewhere?

Here is the output from the debugger window:

=======================
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
ificonsole
Adding source dir: /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/
Adding source dir: /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/
Adding file: /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan/ificonsole
Changing directory to: "/home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan"
Set variable: LD_LIBRARY_PATH=.:
Starting debugger: /usr/bin/gdb -nx -fullname -quiet  -args "/home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan/ificonsole"
done
Setting breakpoints
Debugger name and version: GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Child process PID: 7434
=======================
The difference with my projects with only an application and no library is the last line with the child process.
Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed on June 27, 2018, 09:52:06 pm
Can you enable full logging in the debugger's setting and post the log using code tags?
What terminal are you using?
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix on June 28, 2018, 08:32:25 pm

The terminal I use is ( copied from settings->environment->general settings):  gnome-terminal --disable-factory -t $TITLE -x


Here's the full log:

The last  3 lines of the log were written when I clicked "stop debugger" twice and then kill -9 5087

I see output in the logging that was supposed to go to the terminal window.

Code
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
ificonsole
Adding source dir: /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/
Adding source dir: /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/
Adding file: /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan/ificonsole
Changing directory to: "/home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan"
Set variable: LD_LIBRARY_PATH=.:

[debug]Command-line: /usr/bin/gdb -nx -fullname -quiet  -args "/home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan/ificonsole"
[debug]Working dir : /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4

Starting debugger: /usr/bin/gdb -nx -fullname -quiet  -args "/home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan/ificonsole"
done

[debug]> set prompt >>>>>>cb_gdb:

Setting breakpoints

[debug]Reading symbols from /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan/ificonsole...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
[debug]Copyright (C) 2016 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-linux-gnu".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 200
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> directory "/home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/"
[debug]Source directories searched: /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> set args -d 3 -configdir escape -story escape.dat
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /home/marnix/XVAN 2.3.4/03 - ifi-xvan2-3-4/xvan/ificonsole -d 3 -configdir escape -story escape.dat
[debug][Thread debugging using libthread_db enabled]
[debug]Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[debug]IFIConsole, passing start json, {"configdir":"escape","datadir":".","story":"escape.dat"}
[debug]IFIClient, setting log level to 3

Child process PID: 5093

[debug][New Thread 0x7ffff6cdf700 (LWP 5093)]
[debug]-- XVAN 2.3.4 interpreter --
[debug](c) Marnix van den Bos
[debug]You must escape! version 1.0 - English
[debug]Suddenly you are here. You have no recollection of anything. Your mind is empty, like it just started.
[debug]You are in some sort of a building, but you can also see through it. You faintly see meadows and a blue sky. The building somehow merges with the outside world. It's like your surroundings are not yet finished.You can also make out blue, red and green objects in the near distance and a shiny object that looks like gold.
[debug]Very weird...
[debug]Someone walks into the room. A big nondescript guy. He is carrying a tablet. When he sees you he looks surprised and a bit confused.
[debug]'What's going on? Who put you in here already? The world isn't even finished. They all know that the player object should only be enabled during he final test cases and regression tests.' We're not that far yet!
[debug]He looks at you and smiles. 'I'm sorry buddy. This shouldn't have happened. I'm going to fix this right away.After a few swipes on the tablet screen he starts typing. You hear him mumbling something about 'commenting out' and 'recompiling'.
[debug]And then everything goes black again....
[debug]Hit a key...
[debug]========================= I N T R O D U C I N G  X V A N ======================
[debug]This is a short sample story for XVAN 2.1.It has 7 rooms and 29 objects, including the player and one npc named Fred.The story contains several puzzles and you need to interact with Fred to solve some of them. You have one goal: escape.
[debug]Disclaimer: I wrote this story to illustrate XVAN's possibilities from a technical perspective. It was not my intention to produce a high level piece of prose.
[debug]===============================================================================
[debug][chest room](use chest room)
[debug]This is a room with an exit leading east.
[debug]There is [an old wooden chest](use old wooden chest) here, which is closed.
[debug][lamp](use lamp)[lamp](use lamp)[lamp](use lamp)[lamp](use lamp)[lamp](use lamp)[lamp](use lamp)[lamp](use lamp)>

Trying to interrupt process with pid: 5093; child pid: 5093 gdb pid: 5087

[debug]225 ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: No such file or directory.
[debug]Thread 2 "ificonsole" received signal SIGINT, Interrupt.
[debug][Switching to Thread 0x7ffff6cdf700 (LWP 5093)]
[debug]pthread_cond_timedwait@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:225
[debug]>>>>>>cb_gdb:

Trying to interrupt process with pid: 5093; child pid: 5093 gdb pid: 5087
Trying to interrupt process with pid: 5093; child pid: 5093 gdb pid: 5087
Debugger finished with status 1
Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed on June 28, 2018, 10:49:48 pm
Interesting. C::B didn't try to start the terminal. :(
What is the type of the target you're using?
Can you reproduce this problem with a simple default console project?
Is the pid of the child (your program) correctly detected by C::B?
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix on June 29, 2018, 06:13:28 pm
I build a virtual target called "ifi-xvan"

It has 2 build targets:
- ificonsole which is a console application
- ifigame, which is a dynamic library

The order in the virtual target is opposite what you told me: application first, then library. Otherwise it won't build. It starts building from the bottom up.

All my projects with one target console application build and debug fine.

Regarding the PID:

After the debugger starts it says:
Child process PID: 4228

I cannot find this PID. But when I click the stop debugger button it says: "Trying to interrupt process with pid: 4228; child pid: 4228 gdb pid: 4217"

PID 4217 is ificonsole, when I kill it the debugger stops.

Does this make sense?

(maybe I should just delete the .cbp .depend and .layout files and recreate the project?)

Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed on June 29, 2018, 06:41:42 pm
No it doesn't make sense. Pid 4217 should be the pid of gdb's executable. Killing gdb also stops debugging.

Can you create a simple console project with the wizard and tell me if showing the terminal works in it?
What is the value of Project -> Properties -> Build targets -> ificonsole -> Type?
Is "pause when execution ends" checked?
Title: Re: Can CB use a linux shell script to build a project?
Post by: Marnix on July 01, 2018, 05:00:37 pm

oBFusCATed, you found it!

The "pause when execution ends" was not checked. I checked the box it and now the debug window comes up.

But is it normal behavior when you uncheck the button? I can't find it in the manual.

Thanks for solving this.



Title: Re: Can CB use a linux shell script to build a project?
Post by: oBFusCATed on July 01, 2018, 06:30:06 pm
It is normal, but annoying. I don't know why it is like this.
I have the desire to change it, but I haven't found the time.