How to recompile a '.h file' on mac? - c

I am using a tool that has been written in C or C++.
https://github.com/kern-lab/discoal
I've never used C myself. In one of the files in discoal.h, I want to change: #define MAXSITES 220020 to #define MAXSITES 1100000. The tool manual says that I would have change the MAXSITES define in discoal.h and then recompile. How do I recompile?
I have never used C language before and I am not a Computer science student therefore, do not have much experience in programming either. Therefore, if you could let me know the command to recompile that'll be great. I've provided a link to that tool in case you want to look at the files.

Open a terminal, cd to the directory where the Makefile is, and type make, then hit Enter.
Prerequisites: A C compiler, which comes with Xcode on a Mac, as #Shawn commented.

Related

How to execute a C file in notepadqq for Linux?

I'm trying to run a C file using Notepadqq in Manjaro Gnome edition, but when I try running my script by going to the Run command it opt up a windows that says Special Placeholders
enter image description here
This should be corrected fairly easily via the graphical user interface. No command or file modification should be necessary.
In Nautilus you can right click on the file to open.
I'm trying to run a C file using Notepadqq in Manjaro Gnome edition, but when I try running my script by going to the Run command it opt up a windows that says Special Placeholders enter image description here
To run a C program you need to compile it first, generate an executable and then run it as a normal system command. You cannot run it directly from Notepad++ because as such, it is not still executable. This is generally done with a program called a C compiler (which you don't mention if you have one or not) I figure that you are on a Windows computer, so the variety and availability of C compilers makes it impossible to continue giving you advice. You need to install a compiler, learn how to use it, and then you'll know how to make your C program executable in the system.
I recommend you to read a good programming book in C, like "The C Programming Language" from Brian Kernighan & Dennis Ritchie, to know how to compile a program and your operating system's manual to know how to execute a program.
Edit
Oh, sorry, you said on linux. You have to save your source file (with some name ended in .c) then compile it with something like
$ cc my_hello.c -Wall -o my_hello
where my_hello.c is the name you gave to the C source file, -Wall makes the compiler to be more verbose in explaining your C programming errors and -o my_hello specifies the compiler to output the executable command in a file called my_hello.
(I have represented the system prompt as $ and the screen cursor as _, you don't need to key those symbols) and then
$ my_hello
Hello$ _
(as you didn't end the line with \n, the next system prompt will appear next to your program's last message) to get it printed correctly, just modify your program to appear as
#include <stdio.h>
int main()
{
printf("Hello\n");
/* ^^-- insert the '\n' there */
}

Clion with more than 1 C file

So i have been using VSCode and back there I had only to make new file save as .C and when I pressed the "run" it automaticly created the "exe" file by themself.
This method is important to me because as I am on programming class, I have the A B C D E F ... exercise to run.
I heard Clion was one of the best tools out there for C, and i have a student acc so decided to try. But here when I create a new project it only lets me run the first file, tried to add a new source file but it fails.
Is there any solution ?
Thanks
CLion uses CMake as makefile generator. I think this question is about CMake "language" and not about CLion. With CMake you can create multiple executables but there is no automatic way to do it.
You can't have more than one source file if you want it to run independently in the same project. As you may know there should be only one main function where the program initiates.

Lack of debugging information in, well, debugger

Currently I am using Clion IDE plus latest version of Open Watcom v2 windows 32 bit compiler to develop some 16 bit MS-DOS application. The problem I have is I don't see all required debugging information when using watcom windows debugger (wdw.exe).
Being specific, I see global variables, global and any other types of functions, even those imported from asm files. But well, local variables list is empty all the time. But more importantly - the only c-code I can see is little test.c file which contains only main() function and nothing else except for includes.
What do I need to do to finally get c-level debugging for whole project? What am I missing?
I would be grateful for any help.
All source files is located in one directory, so, they all should be visible to debugger. But it sees only main c file.
Of course I am compiling with -d2 switch, as well as -hw. DEBUG WATCOM ALL is also presented in linker config file before any FILE directives. Reading manuals to compiler and linker... Well, it's nice that I've found many interesting things in manuals, but nothing helped with exactly that issue so far :)
List of compiler switches I currently using:
WCC.EXE:
CALL WCC.EXE -dTEST -bt=dos -0 -za99 -wx -we -mc -zp2 -hw -d2
%SRC_FULL_NAME%
WLINK:
CALL WLINK.EXE #..\CC.LK
CC.LK:
SYSTEM DOS
DEBUG WATCOM ALL
FILE TEST.OBJ
FILE LUTILS.OBJ
FILE LGL.OBJ
NAME TEST.EXE
OPTION ELIMINATE
...

CodeBlocks MinGW on XP noob. Is it possible to overwrite the same exe every time I compile? Further explanation inside

I have looked through both the CodeBlocks and MinGW FAQ and wiki to no avail. As stated above I am a noob.
I want CodeBlocks to act like a Unix compiler in that it overwrites a single output file every time it compiles unless told to do otherwise.
In Unix:
[cc example.c] -> [a.out], [cc example2.c] -> [a.out]. If I want to save the output file from being overwritten i just [cc -o newname example3.c] - [newname.out].
If this is possible with CodeBlocks/MinGW on XP I'd like to know how to do it. If not I would appreciate recommendations for another GUI compiler/IDE that could. Any help is appreciated. Thank you.
I want CodeBlocks to act like a Unix
compiler in that it overwrites..
First of all, C::B isn't a compiler -- it's an IDE. Saying you want C::B to act like a compiler makes no more sense then saying you want vim, emacs, or visual studio to 'act' like a compiler.
Second, you change the name of the final executable by right-clicking a project in your workspace. Goto properties->Build targets tab->select which build target you want to change. On the right side of this you'll see Output filename. Enter the executable filename the linker should output here. Alternatively, you can just navigate to the location of your existing executable and just rename it to something else.
And thirdly, chances are you're not even going to be checking back on this site so I'm probably just wasting my time giving an answer to your post.

How Can I debug a C program on Linux?

I am writing a C language program on Linux and compiling it using GCC.
I also use a Make file.
I want to debug my program. I don't want to debug a single file, I want to debug the whole program.
How can I do it?
Compile your code with the -g flag, and then use the gdb debugger. Documentation for gdb is here, but in essence:
gcc -g -o prog myfile.c another.c
and then:
gdb prog
If you want a user-friendly GUI for gdb, take a look at DDD or Insight.
I guess that you are building from the command line.
You might want to consider an IDE (Integrated Development Environment), such as KDevelop or Eclipse, etc (hint - Eclipse ... ECLPISE ... E C L I PS E).
Use an IDE to edit your code, refactor your code, examine your code - class tree, click a variable, class or function to jump to declaration, etc, etc
And - of course - to debug:
run your code in the IDE
set breakpoints to stop at particular lines
or just step through, a line at a time
examine the call stack to see how you go there
examine the current values of variables, to understand your problem
change the values of those variables and run to see what happens
and more, more, more
p.s as wasatz mentioned- DDD is great - for visualizing the contents of arrays/matrices, and - imo - especially if you have linked lists
You can use gdb-based simple and useful GUI "Nemiver". It can debug your whole module comprising many source files.
Try cgdb
cgdb is a lightweight curses (terminal-based) interface to the GNU Debugger (GDB). In addition to the standard gdb console, cgdb provides a split screen view that displays the source code as it executes. The keyboard interface is modeled after vim, so vim users should feel at home using cgdb.
github repository

Resources