Author Topic: Using code::blocks w/o a project  (Read 12961 times)

Offline dukester

  • Multiple posting newcomer
  • *
  • Posts: 31
Using code::blocks w/o a project
« on: January 27, 2024, 05:04:56 pm »
noob to the *blocks" here!
noob to C as well.
I want to simply compile a single c source code file, without having to go through all the project file stuff etc - like in emacs & geany etc.

Is it possible with code::blocks? TIA ..
--
Duke

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Using code::blocks w/o a project
« Reply #1 on: January 27, 2024, 05:39:23 pm »
noob to the *blocks" here!
noob to C as well.
I want to simply compile a single c source code file, without having to go through all the project file stuff etc - like in emacs & geany etc.

Is it possible with code::blocks? TIA ..
Yep, just create a file in a temp folder like:
Code
#include <iostream>
int main() {
std::cout << "Hello World! Welcome to your first C++ program!" << std::endl; }
and name it HelloWorld.cpp (no spaces)

Start CodeBlocks and use Menu/File/Open or just ctrl-o keys
and hit the compile icon (the gear icon).
Click on the "Build log" tab to make sure no errors occured.
Clik on Menu/Build/Run.
You should see a console open with "Hello World! Welcome to your first C++ program!" as output.

Easier than that is:
Load Codeblocks and do:
If you get messages like: "HelloWorld already exists, do you want to overwrite it?", answer yes.
1) Menu/file/new/project...
2) Double click "Project application"
3) Click on "next" two times. Enter the name "HelloWorld" (no spaces)  in the project title.
4) Click on "next" and "finished"
5) On the Project tab double click "main.cpp" to open the file.
Cl6) Cick on the compile (gear icon) to compile, then  Menu/Build/run (or the  green right-pointing run arrow).

For further reading:
https://www.codeblocks.org/user-manual/
https://www.sci.brooklyn.cuny.edu/~goetz/codeblocks/codeblocks-instructions.pdf (this takes some time to load into a browser). Maybe download it instead.

« Last Edit: January 27, 2024, 05:46:08 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Using code::blocks w/o a project
« Reply #2 on: January 27, 2024, 06:14:23 pm »
I found an even easier way to create the file.
Menu/File/new/Empty file.
Paste the code into the file.
Menu/File/Save as/ c:\temp\HelloWorld.cpp (or any other folder, as long as it's not a protected OS folder.
Menu/Build
Menu/Build/Run

Offline dukester

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Using code::blocks w/o a project
« Reply #3 on: January 27, 2024, 06:28:59 pm »
I did just as you suggested - opened an existing .c source file.
Build & run

I keep getting:

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
||=== Build failed: 0 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
--
Duke

Offline dukester

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Using code::blocks w/o a project
« Reply #4 on: January 27, 2024, 06:32:46 pm »
I found an even easier way to create the file.
Menu/File/new/Empty file.
Paste the code into the file.
Menu/File/Save as/ c:\temp\HelloWorld.cpp (or any other folder, as long as it's not a protected OS folder.
Menu/Build
Menu/Build/Run

Right on! Thx, but I still get that error msg from code::blocks.
--
Duke

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Using code::blocks w/o a project
« Reply #5 on: January 27, 2024, 08:36:30 pm »
I found an even easier way to create the file.
Menu/File/new/Empty file.
Paste the code into the file.
Menu/File/Save as/ c:\temp\HelloWorld.cpp (or any other folder, as long as it's not a protected OS folder.
Menu/Build
Menu/Build/Run

Right on! Thx, but I still get that error msg from code::blocks.
What OS and what version of CodeBlocks are you using?
show us your hello world code inside codetags  (the # above a reply box). 
« Last Edit: January 27, 2024, 08:46:46 pm by Pecan »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1632
Re: Using code::blocks w/o a project
« Reply #6 on: January 27, 2024, 08:43:31 pm »
You must install and configure a compiler.

Offline dukester

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Using code::blocks w/o a project
« Reply #7 on: January 27, 2024, 09:52:23 pm »

What OS and what version of CodeBlocks are you using?
show us your hello world code inside codetags  (the # above a reply box).
[/quote]

gcc --version
gcc (Debian 10.2.1-6) 10.2.1 20210110

 codeblocks -h
Starting Code::Blocks Release 20.03  rev 11983 Feb 20 2020, 19:35:00 - wx3.0.2 - gcc 6.3.0 (Linux, unicode) - 64 bit

Code
cat hello.c
#include <stdio.h>
int main(){
  printf("Hello World from Turner Valley!\n");
  printf("This program was compiled in the emacs editor.\n");
return 0;
}

--
Duke

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Using code::blocks w/o a project
« Reply #8 on: January 27, 2024, 10:06:27 pm »
Make sure that your Menu/Settings/Compiler/ToolChain_executables look like this:
« Last Edit: January 27, 2024, 10:17:17 pm by Pecan »

Offline dukester

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Using code::blocks w/o a project
« Reply #9 on: January 27, 2024, 10:56:16 pm »
Thx for the screenshot!! Yup! Got it set up that way also!
I have zero probs from the CLI / emacs / geany. Compiles like a charm. I just got the notion to test-drive code::blocks! Too much grief it seems.
--
Duke

Offline dukester

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Using code::blocks w/o a project
« Reply #10 on: January 28, 2024, 04:00:43 am »
Easier than that is:
Load Codeblocks and do:
If you get messages like: "HelloWorld already exists, do you want to overwrite it?", answer yes.
1) Menu/file/new/project...
2) Double click "Project application"
3) Click on "next" two times. Enter the name "HelloWorld" (no spaces)  in the project title.
4) Click on "next" and "finished"
5) On the Project tab double click "main.cpp" to open the file.
Cl6) Cick on the compile (gear icon) to compile, then  Menu/Build/run (or the  green right-pointing run arrow).

I just tried your above suggestion for hellery! No joy!
The main.c file got written to the HelloWorld directory, BUT /obj/Release/main.o never gets written so gcc chokes with an error msg.

Quote
/usr/bin/bash: gcc -Wall -O2 -Wall -std=c99 -m64 -Og  -I~/programming/c/code/HelloWorld -I~/programming/c/code/HelloWorld/ -c ~/programming/c/code/HelloWorld/main.c -o obj/Release/main.o: No such file or directory
--
Duke

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Using code::blocks w/o a project
« Reply #11 on: January 28, 2024, 04:11:15 am »
What version of CodeBlocks are you using?
Should show in the splash screen, but you can find it in the Menu/Help also.

Tomorrow, I'll load up Codeblocks in a Linux VM and see what's going on.

Hang in there, bud. You're gonna like CodeBlocks.  :)

I've been using it for Windows, Linux, and embedded coding for 20 yrs. I know any new software is hard to get started using. After that, it flies.

We'll figure this out. I just need to cause the same problems you're having to understand what's going on.


« Last Edit: January 28, 2024, 04:20:42 am by Pecan »

Offline dukester

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Using code::blocks w/o a project
« Reply #12 on: January 28, 2024, 04:40:29 am »
Right on! I'm close to the solution I'm sure!
I've got v20.03 on this Linux antiX box!

Thanks for all your help!
« Last Edit: January 28, 2024, 04:42:32 am by dukester »
--
Duke

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Using code::blocks w/o a project
« Reply #13 on: January 28, 2024, 10:30:12 pm »
I brought up (in a VMware) Linux Mint 21.x:
Name             : Code::Blocks
Version          : 20.03-r11997
SDK Version      : 2.0.0
Scintilla Version: 3.7.5
Author           : The Code::Blocks Team
E-mail           : info@codeblocks.org
Website          : http://www.codeblocks.org
wxWidgets Library (wxGTK port)
Version 3.0.5 (Unicode: wchar_t, debug level: 1),
Runtime version of toolkit used is 3.24.
Compile-time GTK+ version is 3.24.33.

I disabled all plugins except: (via Menu/Plugins/Manage Plugins)
Code
Abbreviations
AutoVersioning
Autosave
BrowseTracker
Compiler
Debugger
DragScroll
Files extension handler
Foreign projects Importer
Header Fixup
Help pllugin
IncrementalSearch
Keyboard shortcuts
OccurrencesHighlighting
Open files list
ReopenEditor
Scripted wizard
SmartIndentCpp
SmartIndentXml
Source Exporter
Source code formatter
ThreadSearch
Todo List
wxSmith
sxSmith-Aui
wxSmith-Contrib Items
wxSmith-MIME plugin

I restarted CB after disabling plugins.
I performed the following.
1) Menu/File/New/EmptyFile
2  copy/pasted your code into the Untiled1 editor.
3) Menu/File/Save as/ into Home/pecan/temp/HellowWorld.c
4) Menu/Build/Build
5) Menu/Build/Run

 The results are in the .jpg attached.

Build Messages
Code
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
||=== Build finished: 0 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Build Log
Code
-------------- Build file: "no target" in "no project" (compiler: unknown)---------------

gcc   -c /home/pecan/Temp/HelloWorld.c -o /home/pecan/Temp/HelloWorld.o
gcc  -o /home/pecan/Temp/HelloWorld /home/pecan/Temp/HelloWorld.o   
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 
Checking for existence: /home/pecan/Temp/HelloWorld
Executing: 'xterm -T '/home/pecan/Temp/HelloWorld' -e '/usr/bin/cb_console_runner' '/home/pecan/Temp/HelloWorld'' (in '/home/pecan/Temp')
Set variable: LD_LIBRARY_PATH=

« Last Edit: January 28, 2024, 10:33:05 pm by Pecan »

Offline dukester

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Using code::blocks w/o a project
« Reply #14 on: January 28, 2024, 10:37:27 pm »
WOW! I'll try disabling all plugins as well except those you kept - and try again. Thanks a bunch for the trouble you went through!
--
Duke