Compile C source file using Command Prompt - c

I am having trouble while using the codeblocks-16.01mingw-setup.exe - installed in a file whose path does not contain spaces - when trying to compile at a comand prompt. A beginner's guide recommended using the following line in command prompt:
gcc cards.c -o cards
for the source file named cards.c (on my desktop). This gives the error
'gcc' is not recognised as an internal or external command, operable program or batch file.
When trying to figure this out, I have found out that you can drag and drop files in your command prompt and it specifies their path. Doing this with the gcc.exe taken from F:\Programare\Codeblocks\MinGW\bin\gcc.exe and adding the c source file as C:\Users\dream\Desktop\cards.c gives the error
as.exe - System error: The program can't start because libintl-8.dll is missing from your computer. Try reinstalling the program to fix this problem.
I've reinstated my Codeblocks to no avail. I've also tried matching the paths of the compiler with the source file, bringing the source code where the compiler was, again to no avail.
Please help me understand the issue. I must say that the file named libintl-8.dll is right there where gcc.exe is, trying to add it in the command prompt gives some syntax error.

gcc is trying to find that dll file in the working directory, so you need to cd into that directory cd /d F:\Programare\Codeblocks\MinGW\bin.
Dynamic-Link Library Search Order (Windows)
The directory specified by lpFileName.
The system directory. Use the GetSystemDirectory function to get the path of this directory.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
The current directory.
The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.

You have to add F:\Programare\Codeblocks\MinGW\bin\ to your users or systems PATH environment variable.
Once you have done this you can simply type
gcc cards.c -o cards

Related

How to refer to a different directory to cmake while running cmake commands from a batch script on Windows

I come from a Linux Unix background and I am trying to covert a very simple .sh to a .bat script.
I want to run a cmake command in a batch file on Windows 10. But I want to run the cmake command from inside of a build directory placed outside the source code directory. The source code directory is just along side the build folder.
::build_something.bat
mkdir build
CD build
cmake ../SourceCodeDir
As you can see above that I want to generate all the build files inside the build/ directory.
But the issue is cmake instead wrongly tries to find the SourceCodeDir directory inside build/ complaining that build/SourceCodeDir does not exist. This indicates that I am doing the directory navigation wrong in the batch script. How should I modify the Unix based folder navigation to a Windows based folder navigation on the batch script?
Following is the exact error that cmake states:
CMake Error: The source directory "C:/code/build/SourceCodeDir" does not exist.
PS:
I am running the batch script from a git bash shell.
I understand that the slashes in directory paths are Linux based but that should not be an issue since I am running it from git bash? Or is that one of the problems in the bat script?

Run c-code with cmake

I am new to programming and I have several c-files I want to run from the terminal in mac. I have installed cmake from homebrew and it seems to be installed correctly (when I type "brew install cmake", I get the message "Warning: cmake-3.6.3 already installed").
My problem is, that I don't know what to type next to compile/run the file. I'm sorry if this seems really basic, but I don't understand the answers I found on Google. I have changed the directory to the folder containing my files "cd /Users/..." and I have a CMakeList.txt file from a friend and put in the same folder.
I have tried typing "cmake ." and it creates a lot of new folders, but I doesn't print anything. I have a "printf"-command in my main.c.
Can anyone tell me, what I should type to make the code print to the terminal?
CMake doesn't run your program.
CMake generates a Makefile. This Makefile can be interpreted by "make" by calling "make" in the same directory (you can also specify other names or paths, but not needed here). "make" will call the compiler, linker and maybe some other stuff to build your program. At the end and with no errors, you have a executable named as written in the "add_executable" instruction in your CMakeLists.txt. To run this program it should be sufficient to type "./program_name" in the build directory.
One hint: It is better to create a subfolder for building. "mkdir build && cd build && cmake ../ && make".

Running Executable

I have an executable that is generated using VC++. The VC++ project includes some of the dlls and when I tried double clicking the exe, it is asking for the path of the dll's.
Is it possible to place the generic dll's into a common folder, open the exe file using the batch file and provide the reference path of the dll's??
See this link for information on DLL search order on Windows.
Quick and incomplete summary:
The directory where the executable module for the current process is located.
The current directory.
The Windows system directory.
The Windows directory.
The directories listed in the PATH environment variable.
Note: The LIBPATH environment variable is not used.
EDIT
To address the comment about having the external DLLs copied locally:
After adding the files to your project, right-click one, select Properties. In the General section, change Item Type to Custom Build Tool. Now in the new section Custom Build Tool, change the Command Line to copy that particular file to the output directory.
You can also do all the necessary file copying in the Pre/Post-build steps of the project.

Help with C Program Executable - Linux

I just recently made the move to Linux, and now looking to program on it as well.
However, for some reason I cannot get an executable to work.
Here's what I've done:
Downloaded Code::Blocks
Made a new Console Project in Workspace 1 with C source.
Added a getchar() before return(0);
Ran and Compiled - Which works perfectly INSIDE Code::Blocks
Went to the bin/release folder in which the file is saved, tried double clicking, right clicking and selecting: open, open with, tried using terminal to run the name of my program. I copied the folder URL, and then name of the file.. I just can't seem to get the created file to execute!
In windows it made a .exe, I know there is no ending (?) in linux. (Could be wrong).
I'm currently running Ubuntu 11.04.
Most Linux distributions don't include the current directory in the PATH variable that determines where to search for executables. Try opening a terminal, changing to the bin/release directory and explicitly qualifying your executable for the current directory:
./myprogram
This is in contrast to Windows, where you can simply type "myprogram.exe".
You might need to grant your program permission to run as an executable:
sudo chmod +x yourProgram
In the terminal emulator, go to (cd) the folder where the executable is created.
Type ./programname
Where programname is the name of the executable file
(./ tells the shell to look in the current directory for the program to run)

C Socket Programming with CygWin

Hi
I'm trying to write a little server / client program in C using CygWin, problem is, the gcc compiler in Cygwin doesn't seem to contain the standard headers assosiated with socket-programming. When trying to compile my server program, i get:
netinet/in.h: No such file or directory
sys/socket.h: No such file or directory
netdb.h: No such file or directory
Are these three headers located elsewhere in the CygWin-enviorment?
I also had same problem.. i was googling for hours and finally found this... thanks to ralph...
https://ralphexe.wordpress.com/2015/09/09/run-unix-socket-program-in-windows-using-cygwin/
For socket commands you have to include some of the packages in cygwin while installing...
(If you have installed try reinstalling ...)
During the installation :
In "SELECT PACKAGES " phase of installation.
Expand DEVEL
select GNU compilers for c and c++
4.And click next and complete the installation.
NOW, try with a socket program involving sys/socket.h ...
I HOPE IT WILL WORK ... :-)..
Try using the -I compiler command line option to specify a path to the header files.
My local reference states
-I dir
Add the directory dir to the list of directories to be searched for
header files. Directories named by -I are searched before the
standard system include directories. If the directory dir is a
standard system include directory, the option is ignored to ensure
that the default search order for system directories and the
special treatment of system headers are not defeated .
At least on my cygwim they are in
/usr/include/sys and /usr/include/netinet
I also had the same problem.
I've resolved to review the compile options.
NG:
$ gcc -mno-cygwin -o echo_server.exe echo_server.c
echo_server.c:12:43: sys/socket.h: No such file or directory
echo_server.c:13:24: netinet/in.h: No such file or directory
OK:
$ gcc -o echo_server.exe echo_server.c
I had this problem for days with the library apophenia .
so make sure the libraries you've installed have first been configured with a simple command
./configure
once configured use the following commands to build , Install and check the libraries
all- Builds libraries
install- installs libraries
check-tests the libraries
doc- generate documentation via doxygen
Hope it helps. :)

Resources