Clion with more than 1 C file - c

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.

Related

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

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.

CodeBlocks - How to add an icon to a C program?

I have a small C console program and I want to add an .ico file to it, so that the executable looks nice.
How can I do this in CodeBlocks with MinGW/gcc?
I could not find relevant help via google that a total beginner (like me for C) could follow, so I will Q&A this topic.
First of all you need an .ico file. Put it in the folder with your main.c file.
In CodeBlocks go to File -> New -> Empty File and name it icon.rc. It has to be visible in the Workspace/Project otherwise CodeBlocks will not be aware of this file. It will show up there in a project folder called Resources .
Put the following line in it: MAINICON ICON "filename.ico". MAINICON is just an identifier, you can choose something different. More info 1 & More info 2.
Save the files and compile - CodeBlocks will do everything else for you
What will happen now, is windres.exe (the Resource Compiler) compiling the resource script icon.rc and the icon to an object binary file to obj\Release\icon.res. And the linker will add it to the executable.
It's so easy yet it took me quite a while to find it out - I hope I can save someone else having the same problem some time.

seeing output of C code in Xcode on mac

I'm using Xcode to write C code. Firstly, it took me for ages to figure out that I need to go to Product->Edit Scheme->Select Executable in order to run C executables.
I have a lot of source files and each one has a main so is there any way to run C source files by just selecting them from left-hand pane and pressing Run? Is there a simpler workflow?
Add new target and select the source file which you need and assign to this target and run.

XCODE error: new file not built

So first I made a new project by going to File> OS X > Command Line Tool and chose C as the language. This is what I got:
Then I made a new C file called program.c:
Then I pressed run. It didn't build successfully:
However, when I deleted the first default file (main.c) and then pressed run program1.c....it built successfully.
My problem: Why can't I have several files under the same project and run them successfully?
Because you will have the main function declared in both files. I do not know how to tell XCode to build two separate applications..
You can't have 2 main functions
Edit: each c program has to contain only one main function.
Other files of that program can not implement another main function.

Xcode change/remove comment template

Recently I've been learning how to program C. For most of the time, I have been using the C version of Eclipse. Recently, I tried out Xcode. I am using a Mac running Mac OS X Lion - Xcode version 4.1.
There is one grievance I have: at the top of every file that I create, there is this little section of comments that I wish to remove or better yet, change.
When I create a file, something like this is put at the top of the file by default:
//
// FILE.c
// PROJECT NAME
//
// Created by Martin Tuskevicius on DATE.
// Copyright YEAR ORGANIZATION (my school name for some reason). All rights reserved.
//
Obviously the things in capitals would be replaced with an actual value. For those of you have use, or have used Xcode, for programming C - do you know a way of how to change or remove these default comments?
I really appreciate any help.
Thanks!
UPDATE:
According to #Michael Dautermann 's comment below, change templates in Xcode.app bundle is not a good way. Check https://stackoverflow.com/a/33743/380774 for more information.
You can remove or change the header in File Templates, I'm using Xcode 4.3, and the File Templates is in /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates.
Please do not edit files inside Xcode, that will break the application signature and will cause Xcode to refuse to start up after the next restart or so.
Create an IDETemplateMacros.plist file containing a dictionary with a FILEHEADER key (string) instead.
You can put the file in
for all users on a single project by dropping it in your project's or workspace's xcshareddata folder (e.g. MyAppWorkspace.xcworkspace/xcshareddata/IDETemplateMacros.plist)
for yourself for a single project by copying it into e.g MyAppWorkspace.xcworkspace/xcuserdata/YOURNAMEHERE.xcuserdatad
global for all projects that you open in your account by dropping the file in ~/Library/Developer/Xcode/UserData/
You can change it in Xcode project File.
This is my image for tutorial :D
Very easy!!!

Resources