I created a plain c project in qt creator using
File->New file or Project->Non Qt Projects->Plain C Project
main.c
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
test.pro
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.c
I build the project using Ctrl+B which was successful. But I am not able to run the project with Ctrl+R.
I earlier used to run the following command to compile and run c program
gcc main.c
./a.out
But Now I am not able to get how to run c program in qt creator.
I am new to Qt Creator. Please Help
Have you set the run settings of your project correctly ?
Make sure to set them like this https://doc.qt.io/qtcreator/creator-run-settings.html
edit: updated link for recent QtCreator version
Seems like the working directory or executable path are missing.
Is there any output given like "could not execute ./a.out : No such file or directory" ?
Related
I have never used Codelite and am attempting to use it as apart of a requirement for "C Programming for Beginners" course on UDEMY.
I am using a Macbook PRO OS version 10.14.5 and Codelite version 14.0.0.
I have created a workspace called SampleApp and within lies a project called Sample with a src file and a main.c file.
The main. c file contains the following code:
#include <stdio.h>
int main()
{
printf("Hello, my name is Link\n");
return 0;
}
When I build the code I get the following output:
/bin/sh -c '/usr/bin/make -j8 -e -f Makefile'
====0 errors, 0 warnings====
Working directory is set to: /Users/link/Desktop/c_code/build-Debug/lib
Executing: open -n -a Terminal /tmp/codelite-exec.sh
Program exited
Unfortunately though, when my terminal pops up I get the following error message:
22:37:07-link#links-MacBook-Pro:~$ /tmp/codelite-exec.sh ; exit;
/tmp/codelite-exec.sh: line 3: cd: /Users/link/Desktop/c_code/build-Debug/lib: No such file or directory
Hit any key to continue...
I am unsure of how to debug this or get this program to run as it appears the target and or the executing directory is not set properly. Kindly advise, thank you.
** UPDATE **
There is no lib folder within /Users/link/Desktop/c_code/build-Debug/lib .. perhaps that's why the code in /tmp/codelite-exec.sh is not working.. Below shows /tmp/codelite-exec.sh - line 2 attempts to change directories to the lib folder and execute the Sample workspace but the lib file doesn't exist..
#!/bin/bash
command="/Users/link/Desktop/c_code/build-Debug/bin/Sample"
cd /Users/link/Desktop/c_code/build-Debug/lib && ${command}
echo Hit any key to continue...```
I've just run into the same problem trying to build a simple wxWidgets HelloWorld with CodeLite before I do anything serious with it. It turns out that this is caused by a default project setting. Open the settings (by right-clicking on your project and selecting settings at the bottom, in case you haven't found this yet). In the General page, find the Execution group and look for Working Directory. It defaults to "$(WorkspacePath)/build-$(WorkspaceConfiguration)/lib", which is pretty silly since that won't be created by default. I changed "/lib" to "/bin" and that error went away.
I tried to compile on windows c program with tenserflow c api and tenserflow.dll from https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip founded on https://www.tensorflow.org/install/lang_c.
This example:
#include <stdio.h>
#include <tensorflow/c/c_api.h>
int main() {
printf("Hello from TensorFlow C library version %s\n", TF_Version());
return 0;
}
Compiling is success, but when i have run it, i recieved a mistake that libtenserflow.so not found. Its look like that tensorfow,dll from https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip was builded with some mistakes for windows sistem, becaurse libtensorflow.so is a target for Linux.
Can you explain or fix this?
I guess it looks for tensorflow.so because you were using GCC tools on VS Code's WSL mode (or other IDEs). But in order to load DLL you need to have Visual Studio.
Here's a simple process to run the Tensorflow for C demo:
Create a new project in Visual Studio;
Configure the project properties(assume the Tensorflow path is C:\tensorflow\; replace it with yours):
C/C++ > General > Additional Include Directories, add "C:\tensorflow\include\"
Debugging > Environment, add "PATH=C:\tensorflow\lib\;%PATH%"
Don't forget the "PATH=" before your tensorflow.dll path.
Compile and run.
You may also add the Tensorflow path to system environment (replace C:\tensorflow\ with your path):
SET PATH=%PATH%;C:\tensorflow\lib\
P.S. If you don't like the Visual Studio IDE and prefer to use Tensorflow with command line mode, try Bazel for Windows instead.
I wrote the following program in Codeblocks
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c;
a = 5;
b = 6;
c = a+b;
printf("Hello world!\n");
return 0;
}
for both debug and release builds. The exe files are created in the respective bin\debug and bin\release folders, and the program works fine when run from codeblocks.
However when I try to execute the exe files form bin\debug or bin\release, I get the libgcc_s_dw2-1.dll is missing from your computer. error.
Searching for libgcc_s_dw2-1.dll only brings out other posts that ask how to fix this problem, where the suggested solution is to either add the path to libgcc_s_dw2-1.dll, which is somewhere inside inthe MinGW installation, to the system path, or statically link the dll file to the program during compilation.
My question is, why is this necessary? This is a very simple hello world program. The file is in a codeblocks project and file extension is .c (main.c, so I'm guessing gcc is automatically invoking the C compiler and it doesn't have anything to do with compiling C code with cpp compiler?) and the compiler settings have been left at their default values after a fresh MinGW and Codeblocks install. Since this program is very simple I am assuming it should work the same way in any other older version compilers as well.
Then what is the use of this dll file? What is happening under the hood when compiling this program? Suppose I compile the hello world program above and distribute the exe file to my friends. How am I supposed to know that I should have statically linked the dll file during compile?
I want to run a simple C script on Ubuntu like this:
xbuild HelloWorld.vcxproj
When I run the script, I get this error:
HelloWorld.vcxproj: error :
/opt/jetbrains/TeamCity/buildAgent/work/d4407e37ceba8427/HelloWorld/HelloWorld.vcxproj:
/opt/jetbrains/TeamCity/buildAgent/work/d4407e37ceba8427/HelloWorld/HelloWorld.vcxproj
could not import "$(VCTargetsPath)\Microsoft.Cpp.Default.props"
This is the script:
#include <stdio.h>
int main(void)
{
printf("Hello world\n");
}
There is a project GCCBuild which you can use to build vcxproj files in Linux. It simple uses same structure of vcxproj but uses GCC to compile and build. There are multiple examples there too.
I've been practicing with writing C extensions for Ruby. It works perfectly on Ubuntu and even when I tried linking to an third party library in my case I used SDL2 and it worked just fine on Ubuntu. When I'm writing C extensions for Ruby on Windows it compiles just fine I get my .so file and everything no errors. But when I test require like this ruby -I. -e "require 'gsdl'" I get an error saying "The specified module could not be found." Why is this how can I get the C extensions to work.
I have Devkit installed and I used Msys and the make that was included in Devkit's bin folder to make the c extention in my project /ext file. My extconf looks like this
require "mkmf"
ext_nme = "gsdl"
dir_config(ext_nme,"C:/Users/my_name/gsdl/SDL/include/SDL2","C:/Users/my_name/gsdl/SDL/lib")
have_library("mingw32")
have_library("SDL2main")
have_library("SDL2")
create_makefile(ext_nme)
and my C extention looks like this
#include <ruby.h>
#include "SDL.h"
void Init_gsdl(VALUE self);
void Init_gsdl(VALUE self){
SDL_Window* window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("Strawberry",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,240,240,SDL_WINDOW_SHOWN);
SDL_Delay(3000);
SDL_DestroyWindow(window);
puts("Gehirn SDL");
SDL_Quit();
}