Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Setting up a C programming environment

Programming languages, Coding, Executables, Package Creation, and Scripting.
Message
Author
fguy
Posts: 33
Joined: 2009-09-04 01:25

Setting up a C programming environment

#1 Post by fguy »

greetings.

I am getting myself set up for C programming on the latest Debian Jessie. In the Debian Reference Manual they recommend the following command to set up the environment.
# apt-get install glibc-doc manpages-dev libc6-dev gcc build-essential

My question is should I be using the package gcc-4.9 instead of just gcc in the above command, in order to get the latest stable version. It's not clear to me what the difference is between the two packages.

https://www.debian.org/doc/manuals/debi ... en.html#_c
https://packages.debian.org/stable/devel/gcc
https://packages.debian.org/stable/devel/gcc-4.9

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: Setting up a C programming environment

#2 Post by ralph.ronnquist »

Code: Select all

apt-cache show gcc

cronoik
Posts: 310
Joined: 2015-05-20 21:17

Re: Setting up a C programming environment

#3 Post by cronoik »

Hi,

the difference between gcc-4.9 and gcc is, that gcc is a meta package which depends on the latest avaiable gcc version (which is gcc-4.9 in the jessie repos). So if you need explicit the 4.9 version you should install the gcc-4.9 package.
Have a nice day!

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: Setting up a C programming environment

#4 Post by ralph.ronnquist »

Well, gcc-4.9 does not install cpp, which comes with gcc. However, build-essential depends on gcc, so it'll be installed anyhow, and all in all you wouldn't have needed to be confused at all about which to install.

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Setting up a C programming environment

#5 Post by tomazzi »

There's a bug in jessie repositories: gcc should be a "meta-package" referencing the gcc v4.9.2-10 but it is claiming that it'll install the gcc v4.9.2-2

Most likely, it'll install the gcc v4.9.2-10, simply because only the package name was not updated yet, but the safest way is to directly install the gcc v4.9.2-10 package.

Also, You should make sure to install gcc-doc or better gcc-4.9-doc package to have the manpage for gcc.

Regards.
Odi profanum vulgus

fguy
Posts: 33
Joined: 2009-09-04 01:25

Re: Setting up a C programming environment

#6 Post by fguy »

Well, I'm just learning C, so I don't suppose it really matters whether I have gcc v4.9.2-2 or gcc v4.9.2-10, assuming there really is a v4.9.2-2 in the first place. Also I expect that gcc is important enough that is there really was a critical bug in the repository that someone would have picked up on it by now.

So, when it's all said and done, my inclination is to just follow the command as it appears in the reference manual, which installs gcc the metapackage. If something goes wrong it ain't the end of the world.

Thanks for the replies.

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Setting up a C programming environment

#7 Post by tomazzi »

Definitely there's no a big difference between compilers at the learning stage - but those differences are becoming just huge at a professional level (like f.e. the way of handling bitfields or transparent structures)

You've asked about the gcc v4.9 and You've got the answer - responsiblity is on Your side ;)

Regards.
Odi profanum vulgus

fguy
Posts: 33
Joined: 2009-09-04 01:25

Re: Setting up a C programming environment

#8 Post by fguy »

Well, just to close the book on this ...

I ended up installing gcc using the following command apt install gcc libc6.dev gcc.doc

I didn't go with the build-essential because it said on debian.org that you only needed that if you are developing debian packages.

Anyways, gcc -v shows gcc version 4.9.2 (Debian 4.9.2-10) which I guess is what I wanted.

Also I managed to compile and run a simple C program so I guess all is well.

Is there anything I missed?

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: Setting up a C programming environment

#9 Post by ralph.ronnquist »

You may want to learn and use make as well, and also of course version control, though I might be too old-fashioned to give a good pointer on that; perhaps mercurial could be a choice.

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Setting up a C programming environment

#10 Post by tomazzi »

ralph.ronnquist wrote:You may want to learn and use make as well, and also of course version control, though I might be too old-fashioned to give a good pointer on that; perhaps mercurial could be a choice.
No.

@fguy:
I understand that You've just started the learning process - so You should follow the *right* suggestions.

Make: (or cmake, or derivatives) don't use it: it's just an outdated build system, with a lots of bugs/problems. If your project will grow to the point where a build system is starting to become necessary -> learn autotools (autoconf/automake/libtool). Make build system is a crap - it fails in so many scenarios that i'll be just a waste of time to even try to discuss it.

Mercurial: advertisements are sounding good, but literally (almost) *nobody* is using it. Serious developers are using svn or git. (sourceforge.net or github.com)

Now back to the topic:
Sooner or later Your project(s) will grow in the sense of the number of lines and files. Imagine that one day You'll need to modify/change a structure which is used/referenced 125 times in different src files or headers - this is happening quite often with software projects - then what?

Most of the forums are spreading bullshits about "how to write programs in <some language>" - as most of the answers are: You can just use a text editor.

Well, for a "hello world" that could be fine.

My latest project has about 30'000 lines of code and ~60 files. It's simply impossible to use a dumb text editor for such project - even such trivial thing like changing some global variable name would take minutes (at best).

This is where IDEs are coming in - and sooner or later You'll be sentenced to use one of such programs.

There are plenty of IDEs, which are sometimes called "smart editors" - like EMACS - but the truth is: You'll need some kind of an IDE to efficiently write the code.

My suggestion is: it's better to start writing Your code in some IDE, because f.e.syntax highlighting will make the learning process faster.

Regards.

PS.
I'm using Code::Blocks IDE for years - it does the job for me.
Odi profanum vulgus

fguy
Posts: 33
Joined: 2009-09-04 01:25

Re: Setting up a C programming environment

#11 Post by fguy »

Thanks for the tips. Yeah I am using Code::Blocks v 13.12 that I got from jessie-backports. CB worked great for me when I was using Windows, but now that I have switched to Jessie 8.4 running Xfce v4.10 desktop, CB is acting a little flaky, occasionally just shutting itself down and I lose unsaved work. I'm not sure what the problem is, but I am starting to look for an alternative.

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Setting up a C programming environment

#12 Post by tomazzi »

fguy wrote:Thanks for the tips. Yeah I am using Code::Blocks v 13.12 that I got from jessie-backports. CB worked great for me when I was using Windows, but now that I have switched to Jessie 8.4 running Xfce v4.10 desktop, CB is acting a little flaky, occasionally just shutting itself down and I lose unsaved work. I'm not sure what the problem is, but I am starting to look for an alternative.
Code::Blocks project is now switching from wxwidgets 2.8.x to 3.1.x - this is a long process. Unfortunately, the only way to get latest "stable" build is to not use the versions which are available in the repos - the stable C::B can be obtained from nightly builds - but that's another story...

Anyway, it was was just an example - there're other stable IDE's - like f.e. Eclipse + CDT, but this is not the point here - You need an editor with a dependancy tracking, based on a variable symbol definitions - an IDE.

Regards.
Odi profanum vulgus

fguy
Posts: 33
Joined: 2009-09-04 01:25

Re: Setting up a C programming environment

#13 Post by fguy »

tomazzi wrote:
fguy wrote:Thanks for the tips. Yeah I am using Code::Blocks v 13.12 that I got from jessie-backports. CB worked great for me when I was using Windows, but now that I have switched to Jessie 8.4 running Xfce v4.10 desktop, CB is acting a little flaky, occasionally just shutting itself down and I lose unsaved work. I'm not sure what the problem is, but I am starting to look for an alternative.
Code::Blocks project is now switching from wxwidgets 2.8.x to 3.1.x - this is a long process. Unfortunately, the only way to get latest "stable" build is to not use the versions which are available in the repos - the stable C::B can be obtained from nightly builds - but that's another story...

Anyway, it was was just an example - there're other stable IDE's - like f.e. Eclipse + CDT, but this is not the point here - You need an editor with a dependancy tracking, based on a variable symbol definitions - an IDE.

Regards.
I see on the CODE::Blocks download page there is a link to a file codeblocks_16.01_amd64_jessie.tar.xz which is their latest official release so maybe I'll give that a try. I'd like to stay with CB if I can, programming is my main hobby and I like to stay with things that have worked for me in the past. Unfortunately, I am even more of a rookie at Linux than I am with C, so I'll have to do some homework before I attempt an install that is not using the APT system

den4oman
Posts: 13
Joined: 2016-04-07 22:35

Re: Setting up a C programming environment

#14 Post by den4oman »

On windows i have used Notepad++ , which i think is better than code::blocks and when i moved on Debian, this was one of the first things for which i've looked to see if there was ported version. Then i saw what i can do with a terminal and that was... :D
Take a look at this one:
https://atom.io/
I personally find it very useful. This editor with gcc in terminal is my recommendation, all you need is:
gcc [...] `pkg-config --cflags somelibrary` hello.c -o hello `pkg-config --libs somelibrary` [...]

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Setting up a C programming environment

#15 Post by tomazzi »

den4oman wrote:On windows i have used Notepad++
Nope, on winblows people are using notepad2-mod - if they need a simple but robust text editor.
...
That's because Microshit wasn't able to develop even such a simple thing like a text editor for the last ~25 years. Their "notepad" is improperly using their own GDI interface - it is blinking like a crazy during window resizing - shame like hell.
Zero support for non-native encodings, fails even with standard ASCII (inability to display special characters) and slows down incredibly when the opened file has just few hundreds of kilobytes - do they really hiring software developers?
...
But, btw, it's only an example which is showing that Microshit is unable to create serious software - usually they are just stealing some solutions or (in much rarest cases) - buying particular solutions, and if this is not helping - they can always spread some kind of a FUD...
den4oman wrote:On windows i have used Notepad++ , which i think is better than code::blocks
This editor with gcc in terminal is my recommendation, all you need is:
gcc [...] `pkg-config --cflags somelibrary` hello.c -o hello `pkg-config --libs somelibrary` [...]
Bullshit - You have simply no idea what You're talking about.
But what's worse - most likely You've never even launched the C::B - otherwise You would know about its excellent interfaces to GDB, GCC, !! linker !!, Valgrind, etc...
Odi profanum vulgus

den4oman
Posts: 13
Joined: 2016-04-07 22:35

Re: Setting up a C programming environment

#16 Post by den4oman »

tomazzi you're talking about this one https://notepad-plus-plus.org/ ,right?
On Windows i used it , so i can open every type of file, so i can't agree with u about encoding.
I have mistake - i used DevCpp , not Notepad++ for compiling and that was a really a long time ago - on middle High School level, so i'm sorry about talking like that about Code::Blocks. I can't give an abstract point of view. It is really good IDE and i recommend it too ... :oops:
What i wanted to say is that the Atom editor is really interesting - you didn't said anything about it.
And that gcc in terminal is what you should do - because it can give you a lot of useful skills. If you want to write in C , you'll probably want a low level of everything ... ( i think )

PS. Again sorry for the comment about Code::Blocks ...
PSS. The year was around 2009 when i last used Code::Blocks/DevCpp/Notepad++

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: Setting up a C programming environment

#17 Post by ralph.ronnquist »

@tomazzi: being right, or not, is not an excuse for being aggressive.

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Setting up a C programming environment

#18 Post by tomazzi »

ralph.ronnquist wrote:@tomazzi: being right, or not, is not an excuse for being aggressive.
Do You mean this?
Bullshit - You have simply no idea what You're talking about.
But what's worse - most likely You've never even launched the C::B (...)
Well, bullshits is bullshit, no matter how You are going to call it. Your definition of agression is apparently broken.
den4oman wrote:tomazzi you're talking about this one https://notepad-plus-plus.org/ ,right?
On Windows i used it , so i can open every type of file, so i can't agree with u about encoding.
No. Please read with understanding.

-----------------------------------
den4oman wrote:What i wanted to say is that the Atom editor is really interesting - you didn't said anything about it.
I don't know that editor. But it's not an IDE - therefore I'm not really interrested to try another tabbed editor clone, especially that all of them are based on the same solution: scintilla.
den4oman wrote:And that gcc in terminal is what you should do - because it can give you a lot of useful skills. If you want to write in C , you'll probably want a low level of everything ... ( i think )
List that "useful" skills please...

I can start with the first one:
An ability to stop yourself from crashing the monitor off the wall, after You realized that a little mistake requires partial recompilation of the project, and You need to write that long list of gcc and linker options again, without making another mistake ;)
Odi profanum vulgus

den4oman
Posts: 13
Joined: 2016-04-07 22:35

Re: Setting up a C programming environment

#19 Post by den4oman »

@tomazzi
You are the one who need to read carefully, i'm talking about the one with the url i posted.... And i also wrote that it was a really long time ago ...

About the skills:

make mistake -> remember what cause it -> don't make it next time ; )

As i said
If you want to write in C , you'll probably want a low level of everything ... ( i think )
If you think gcc in terminal is useless ... please tell me what C programs you're making ?

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Setting up a C programming environment

#20 Post by tomazzi »

den4oman wrote:@tomazzi
You are the one who need to read carefully, i'm talking about the one with the url i posted....
I was talking about Notepad, not Notepad++... never mind.
den4oman wrote:If you think gcc in terminal is useless ...
Yes, gcc used in teriminal by manually issuing all the options is next to useless - and definitely It won't teach You anything.

Using of gcc in terminal can be good for a "hello world" or at a very early stage of learning, but otherwise it's just a waste of time, productivity and it'll be source of many, sometimes undetectable, errors (especially the order of linking of the object files)

*ALL* software projects in the world are using scripts which are in turn invoking gcc to compile the code.
The scripts are either generated by autotools or by IDEs or in a mixed way: the IDE can be used to configure autoconf/automake which in turn will create the final script.

This is how it works, no matter if it's EMACS, Code::Blocks, Eclipse or whatewer.

And to show You a sample, here is a set of commands needed to compile a relatively small program (exactly 5515 lines of code).
This is a debug mode, in which most of specialized gcc options is not used (to avoid confusing the debugger):

Code: Select all

gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/devices/mal.c -o target/obj/src/devices/mal.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/devices/mal_cnv.c -o target/obj/src/devices/mal_cnv.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/sdcs_HC/client_db.c -o target/obj/src/sdcs_HC/client_db.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/sdcs_HC/daq_hc.c -o target/obj/src/sdcs_HC/daq_hc.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/sdcs_HC/devcon_hc.c -o target/obj/src/sdcs_HC/devcon_hc.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/sdcs_HC/hc_main.c -o target/obj/src/sdcs_HC/hc_main.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/sdcs_HC/host.c -o target/obj/src/sdcs_HC/host.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/shared/compstr.c -o target/obj/src/shared/compstr.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/shared/connection.c -o target/obj/src/shared/connection.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/shared/dynarr.c -o target/obj/src/shared/dynarr.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/shared/iface.c -o target/obj/src/shared/iface.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/shared/log.c -o target/obj/src/shared/log.o
gcc -Wall -pthread -Wextra -g -DDBG_LEVEL_0_off -DDBG_LEVEL_1 -DDBG_LEVEL_2  -c /home/tomazzi/ProgLinux/SLiMDCS/src/shared/protocol.c -o target/obj/src/shared/protocol.o
g++  -o target/sdcs_hc target/obj/src/devices/mal.o target/obj/src/devices/mal_cnv.o target/obj/src/sdcs_HC/client_db.o target/obj/src/sdcs_HC/daq_hc.o target/obj/src/sdcs_HC/devcon_hc.o target/obj/src/sdcs_HC/hc_main.o target/obj/src/sdcs_HC/host.o target/obj/src/shared/compstr.o target/obj/src/shared/connection.o target/obj/src/shared/dynarr.o target/obj/src/shared/iface.o target/obj/src/shared/log.o target/obj/src/shared/protocol.o  -Wl,--hash-style=gnu -z relro  -lrt -lcxc -ltxtconf
den4oman wrote:... please tell me what C programs you're making ?
The above compiles a threading server, which is part of bigger project, but the code is not released yet. (I'll finish this in a month or two I think)
However, if You wish, You may take a look at the code of the cxc lib, which is one of the key components of the project.

Regards.
Odi profanum vulgus

Post Reply