Starting the debuggee failed: No executable specified, use `target exec' - c

Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
// to generate numbers
void gen_data(int b[], int n)
{
int i;
for (i = 0; i < n; i++)
b[i] = rand() % 101;
}
// to display numbers
void disp_data(int b[], int n)
{
int i;
for (i = 0; i < n; i++)
printf("%d \n", b[i]);
}
// insert at desired posn
void insert(int b[], int n, int elt, int pos)
{
int i;
for (i = n - 1; i >= pos; i--)
b[i + 1] = b[i];
b[pos] = elt;
}
// delete an elt at given position
void delete (int b[], int n, int pos)
{
int i;
for (i = pos + 1; i < n; i++)
b[i - 1] = b[i];
}
// driver code
int main()
{
int a[100], pos, n = 10, let;
int opt;
system("cls");
gen_data(a, n);
while (1)
{
printf("\n 1- Insert 2-Delete 3-Display 4-quit\n");
scanf("%d %d", &pos, &elt);
insert(a, n, elt, pos);
n++;
break;
case 2:
printf("enter position at which elt to be deleted: ");
scanf("%d", &pos);
delete (a, n, pos);
n--;
break;
case 3:
printf("the numbers are : \n");
disp_data(a, n);
break;
}
if (opt == 4)
break;
} // end while
}
Log:
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Users\Ranju\Desktop\you\lab pro\
Adding source dir: C:\Users\Ranju\Desktop\you\lab pro\
Adding file: C:\Users\Ranju\Desktop\you\lab pro\bin\Debug\lab pro.exe
Changing directory to: "C:/Users/Ranju/Desktop/you/lab pro/."
Set variable: PATH=.;C:\MinGW\bin;C:\MinGW;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C;C:\Users\Ranju\AppData\Local\Microsoft\WindowsApps;C:\Program Files\CodeBlocks\MinGW\bin
Starting debugger: C:\Program Files\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet -args "C:/Users/Ranju/Desktop/you/lab pro/bin/Debug/lab pro.exe"
done
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 8.1
Starting the debuggee failed: No executable specified, use `target exec'.
Debugger finished with status 0

In my case, removing space(s) from the project path resolved the problem. Maybe you should try to change path like this:
"C:/Users/Ranju/Desktop/you/labpro/bin/Debug/lab pro.exe"

I recently had the same issue when starting to use CodeBlocks on Windows10 (C::B version 20.03 in my case). The problem was that I also had MinGW installed long before I installed CodeBlocks and CodeBlocks took the gdb.exe from that path instead of taking it from the MinGW path that was installed within CodeBlocks.
The solution for me was to change the default executable path in Settings -> Debugger... -> GDB/CDB debugger -> Default to the gdb.exe that was installed when I installed CodeBlocks. So: <C::B_installation_path>\MinGW\bin\gdb.exe.
After that change, the problem was solved.

I don't know how relevant this may be, but I seem to have the same or similar problem. See the material at
How do you debug using 'Code::Blocks 20.03' (the "mingw" version)?
especially that after the sentence, I have hopefully made progress towards an answer..
I have now added a proper answer to the above question..
I asume that you have MinGW installed, in the directory C:\MinGW.
Perhaps, AT YOUR OWN RISK, you could try temporarily renaming the folder C:\MinGW to something else, and try running the debugger.
I had MinGW pre-installed, when I installed Code::Blocks 20.03 using codeblocks-20.03mingw-setup.exe ( the 8th April 2021 version , default installation accepted). I also had a problem debugging. There is now a fix for this, which seems quite general, applying even without a pre-installed MinGW, see the answer to the other question ( link provided above ).
The fix involves changing a debugger setting, but in your case, you seem to be trying to use the correct debugger, see the line that you give, which is shown just below
Starting debugger: C:\Program Files\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet -args "C:/Users/Ranju/Desktop/you/lab pro/bin/Debug/lab pro.exe"
In the above, you appear to be trying to use a debugger, from the directory, C:\Program Files\Codeblocks\MinGW\bin, which seems O.K., rather than one from C:\MinGW\bin, which is where the debugger was, that I was trying to use, see the other question.
However, you may be using something other than the debugger from the directory C:\MinGW.
Whether or not you have MinGW installed in C:\MinGW, you may need to alter some Setting in Code::Blocks.

I also had this problem. I am currently running Code::Blocks 17.12 on Windows 10. In my case, I simply upgraded my compiler to Mingw64 bit. To fix: I changed an entry in the default.conf file located in c:\users\logonname\appdata\roaming\codeblocks
directory. After making a copy of the original file I changed the line corresponding to the old debugger, gdb32.exe to the new file gdb.exe in its new directory. That fixed the problem. This was the default.conf old line, before making my change: <![CDATA[C:\Program Files (x86)\CodeBlocks\MinGW\bin\gdb32.exe]]>.

Related

Codeblocks C Debugging

I've got a new challenge to return the factorial of a number. Got ideas on how to do this, but the challenger has given some starting code - which is shown below.
Now this isn't how I would have started it (with my extremely limited experience!) - BUT I wasn't sure how system would grab some text & place within an int array - hence I tried running it within codeblocks, debugging and looking at the watch table. However I can't see 'num'.
So I tried copying num to num1:
int num1[30] = {0};
memset(num1[0],num[0], sizeof(num));
that doesn't seem to affect anything...
So question really is - is there something wrong with my codeblocks config (it debugs other programs and I've tried both cygwin & MiniGW) or is there another reason for this behavious?
#include <stdio.h>
#include <string.h>
void FirstFactorial(int num[]) {
// code goes here
printf("%d", num);
}
int main(void) {
// keep this function call here
FirstFactorial(gets(stdin));
return 0;
}

Xcode Seemingly Unable to Use Arrays in C

It's very likely that this is user error as I'm somewhat new to Xcode, but I can't figure this out. Hopefully one of you can.
I'm trying to add an array using the following code:
int ArraySum (int MyArray [], int size) {
int sum = 0;
for (int i = 0; i< size; i++) {
sum = sum + MyArray [i];
}
return sum;
}
int main (){
int mynumberarray [6] = {1,2,3,4,5,6};
int the_sum = ArraySum (mynumberarray, 6);
printf ("The Sum is = %d \n", the_sum);
return 0;
}
When I click the build & run button in Xcode, the only output I get is (lldb).
This would typically lead me to believe that I made a mistake somewhere, but when I run the code through Terminal it runs perfectly and gives me the correct sum.
Can anyone help me here? This isn't an isolated incident, I've had several issues working with arrays in Xcode that are working perfectly when executed in Terminal.
Screenshot:
You have breakpoints set in your Xcode project, so the program is pausing at the first breakpoint and giving you the (lldb) debugger prompt. Disable the breakpoints and run and everything should behave as expected. You can either manually disable each breakpoint (by clicking on it - it should then become dimmed), or go to Debug => Disable Breakpoints in the menu bar.

File Finder in C

First of all Sorry for my bad English. I am not native English.
I am going to write a program that list all available logical disk drives. Then ask the user to select a drive. then takes a file extension and searches that file type in given drive (including directories and sub-directories). Program should be able to run on windows xp and onward. It should be single stand alone application. I am not expert in C. I have some hands on C#. i have following questions in this regard.
1. Is there any IDE/Tool in which i can write C# like code that directly compiles to single stand alone application for windows?
2. Can you recommend some libs that i can use state forward for this purpose like using in C#? (I have seen dirent and studying it.)
I coppied some code that i am testing as a startup.
#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>
#include<conio.h>
#include<dirent.h>
//------------------- Get list of all fixed drives in char array. only drive letter is get. not path.
// add ":\" to build path.
char AllDrives[26];
DWORD GetAllDrives()
{
int AvlDrives=0;
DWORD WorkState=-1;
//TCHAR DrivePath[] = _T("A:\\"); //Orignal Type
//start getting for drive a:\ to onward.
char DrivePath[] = {"A:\\"};
//http://www.tenouk.com/cpluscodesnippet/getdrivetype.html
ULONG uDriveMask = _getdrives();
if (uDriveMask == 0)
{
WorkState=GetLastError();
printf("\r\nFailed to Get drives. Error Details : %lu", WorkState);
return WorkState;
}
else
{
WorkState=0xFF;
printf("The following logical drives are being used:\n");
while (uDriveMask) {
if (uDriveMask & 1)
{
UINT drvType=0;
drvType = GetDriveType(DrivePath);
if(drvType==3)
{
AllDrives[AvlDrives]= DrivePath[0];
AvlDrives++;
printf("\r\n%s",DrivePath);
}
}
++DrivePath[0]; //Scan to all scanable number of drives.
uDriveMask >>= 1;
}
}
return WorkState;
}
int main(int argc, char* argv[]) {
char DrivePath[]={"C:\\"};
char CurrentDrive[]={"C:\\"};
DWORD Drives=-1;
int d=0;
for( d=0; d<26; d++)
AllDrives[d]=' ';
Drives=GetAllDrives();
if(Drives >0)
{
int Length= sizeof(AllDrives);
for(int x=0; x<26; x++)
{
if(AllDrives[x]!=' ')
{
printf("\r\nFixed Drive : %c",AllDrives[x]);
}
}
}
getch();
}
You can use visual studio compiler to compile C and C++ in Windows, and it is available with its own IDE. When you install visual studio, it will install required libraries also to compile the C/C++ program. There are other IDEs and compilers available compatible with Windows like DevC++,CodeBlocks.

Develop C with multiple main entry points

I used to develop Java project by Eclipse.
A Java project can contain many code files with the main function (the entry point), so we can run each code file which has a main function.
But now I want to develop C project by Eclipse CDT.
In a C project we can have only one main function. Can I have many code files with a main function and run each file just like I would in Java?
P.S.: I don't like to write Make Target for each file by main self
Javas option to have a main in every object is highly irritating and does not make sense to me.
I assume you want to train a bit in c and want to find a way to have all training lessons in one file. Here is an option that would do that for you in a crude way. This would not be reasonable to do as an application but you can use this to execute different options.
To use this you would call your program like 'progname 1'.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int ProgrammingLesson001(void);
int main(int argc, char * argv[])
{
int i;
int option;
int e = 0;
printf("%i\n", argc);
for(i = 0; i < argc; ++i)
{
printf("%s\n", argv[i]);
}
if(2 == argc)
{
option = atoi(argv[1]);
printf("Your Option was '%s' interpreted as %i\n", argv[1], option);
}
else
{
option = 0;
e |= 1;
}
switch(option)
{
case 0:
printf("zero is an error\n");
e |= 1;
break;
case 1:
e |= ProgrammingLesson001();
break;
default:
break;
}
if(0 != e)
{
printf("an error has occureed\n");
}
return e;
}
int ProgrammingLesson001(void)
{
printf("This could behave like a main for training purposes\n");
}
If you spent some time programming in c take a second look at makefiles.
You can create a makefile that will fit all your programs.
This reduces the actual work you need to put into this so much that maintaining the switch construct is harder than creating a new project.
Thank Clifford to fixed my quest and guys who replied
I have solved this problem by myself
Here is my solution:
#!/bin/bash
SourceFile=$1
Path="$(dirname "$SourceFile")"
ParentPath="$(dirname "$Path")"
OutputPath="$ParentPath/bin"
OutputFile="$OutputPath/a.out"
mkdir -p $OutputPath
rm -f $OutputFile
gcc -w $SourceFile -lm -o $OutputFile
$OutputFile
This bash's name is gcc.sh
In eclipse run -> external tools -> external tools configurations -> new a configuration
Location: /home/xxxxx/gcc.sh
Working Directory: (just let it be empty)
arguments: ${resource_loc}
Then you can run C file by your customize command

Why all these errors when building this C project?

I'm coding some similar programs in C as part of an XCode project. As this new program needs to exhibit some slightly different functionality to what the 1st working iteration was, I thought targets were the best thing to use.
So I tried to create a new target, and did it the way I thought was the right way from googling how to (in XCode). But on compilation, I get way too many errors.
Here is a screen of the errors I get:
I see that it's having a problem with loads of different characters, so I'm sure it's probably a simple problem like some missing files. But I didn't know what to Google so I hope it's okay that I'm asking.
On a related note, does anyone know why my first version of the program, called main.c, didn't need to include a header file like the one above did?
Thanks!
EDIT:
Here's the code from the new target, which is practically identical to the so far unchanged first version of the program:
/*
* ScalarProduct.c
* Concurrency_Practical1
*
* Created by Chucky on 11/03/2012.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/
#include "ScalarProduct.h"
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
//the final answer
int finalScalarProd;
//random variable
int rand_seed=10;
int rand()
{
int n;
n = random()%11;
//printf("%d\n", n);
return(n);
}
void* getScalarProduct(void *arg)
{
//index for loop
int i;
//scalarProduct of 10 integers
int * scalarProd = (int *) arg;
//my two arrays
int list1[10];
int list2[10];
for (i=0; i<10; i++) {
list1[i] = rand();
list2[i] = rand();
*scalarProd += list1[i]*list2[i];
printf("%d:\t\t %d\t\t %d\t\t %d\t\t\n", i, list1[i], list2[i], list1[i]*list2[i]);
}
return((void*)scalarProd);
}
int main (int argc, const char * argv[]) {
// insert code here...
pthread_t t1, t2;
int sp1= 0, sp2 = 0;
printf("Index\t List1\t List2\t Product\n\n");
pthread_create( &t1, NULL, getScalarProduct, &sp1);
pthread_create( &t2, NULL, getScalarProduct, &sp2);
pthread_join( t1, NULL);
pthread_join( t2, NULL);
printf("\nScalar Products: %d %d\n", sp1, sp2);
finalScalarProd = sp1 + sp2;
printf("Result: %d\n", finalScalarProd);
return 0;
}
From the errors, it almost looks as if you are mixing Objective-C headers and compiling with the C compiler. It's still hard to tell though.
Your project is including/importing the AppKit-Header, which is ObjectiveC and not pure C.
As your quoted source does not mention it, I would bet that it is imported within the precompiled header. Check your project's precompiled header for such entry/ies. It will be named just like your project, with the extension .pch. You may want to remove any ObjectiveC imports.
Also check if you used any ObjectiveC frameworks in your project. When in doubt, remove all listed frameworks from your project.

Resources