Can't configure C in Visual Studio Code, Windows - c

Hi I am getting the following error when I try to run a simple Hello World code in VS code
[Running] cd "c:\Users\nokni\FirstProgram\" && gcc HelloWorld.c -o HelloWorld && "c:\Users\nokni\FirstProgram\"HelloWorld
c:/users/nokni/new folder/library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find c:/users/nokni/new: No such file or directory
c:/users/nokni/new folder/library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find folder/library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o: No such file or directory
collect2.exe: error: ld returned 1 exit status
Any idea why?

The error messages are clearly showing that they are expecting two locations:
c:/users/nokni/new
and
folder/library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o
This should be very indicative that the folder "new folder" is not correctly recognised in the path. The directory name should have been properly escaped or embedded in quotes:
"c:\users\nokni\new folder\library\mingw-w64\..etc.."
or
c:\users\nokni\"new folder"\library\mingw-w64\..etc..

Related

C program is not running on Visual Studio Code

[Image][1]I am using an Ubuntu machine. I want to run C program on Visual Studio code. I have installed C/C++ extension and CODE RUNNER extension to my VS Code. But when I am going to run a simple program, it is showing me errors. What should I do now ?
tony#Jarvis:~/Desktop/c program$ cd "/home/tony/Desktop/c program/" &&
gcc Hello World.c -o Hello World && "/home/tony/Desktop/c program/"Hello World
gcc: error: Hello: No such file or directory
gcc: error: World.c: No such file or directory
gcc: error: World: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Your file name should not contain any spaces. I see Hello World.c. This will not work. Try changing it to HelloWorld.c
Your file name has spaces, Hello World.c. Having spaces while using a Command Line too like gcc is not good. Stay away from spaces as much as you can. In this case gcc thinks that Hello and World.c are separate files.

I'm very very new at coding and I can't run my first C code

I'm very new at coding. I dowloaded VSCode to practice C.`I copied a line of code from the internet, the "Hello World". As I try to run it, my terminal shows this:
none
C:\Users\Selene_514\Desktop\C CPP>cd "c:\Users\Selene_514\Desktop\C CPP" && gcc hello.c -o hello && "c:\Users\Selene_514\Desktop\C CPP"hello
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status.
I installed MinGW and changed the environment path properly. What should I do?

Linker Error (LNK2019) undefined reference to __imp_

I am working on open62541 open source project.I have built the project using Cmake as mentioned here at the following webpage open62541.org and generated the open62541.c ,open62541.h files in the project's build folder.Then I created a new folder called C_project inside the build folder and copied the generated files into this folder.
Now I am trying to build a minimal server(C_Project/myServer.c) by following the steps given at the following page open62541/sever.I am getting the following link errors.
C:\SPB_Data\open62541\build\C_Projects\OPC_UA>cmd /c gcc -std=c99 open62541.c myServer.c -lws2_32 -o myServer.exe > output.txt
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x98): undefined reference to `__imp_UA_ServerConfig_setMinimalCustomBuffer'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0xd8): undefined reference to `__imp_UA_Log_Stdout'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x132): undefined reference to `__imp_UA_Server_new'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x146): undefined reference to `__imp_UA_Server_getConfig'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x165): undefined reference to `__imp_UA_Server_run'
C:\Users\PAVAN-~1\AppData\Local\Temp\cc1s9pOw.o:myServer.c:(.text+0x178): undefined reference to `__imp_UA_Server_delete'
collect2.exe: error: ld returned 1 exit status
I used the following command to build the project:
$ gcc -std=c99 open62541.c myServer.c -o myServer
I tried to find the solutions for this by searching in the web. The only thing that I could get out of that is it might be a error due to dll files. Kindly help.
-open62541.lib specifies that the result of compilation should be written to file pen62541.lib.
And -o myServer.exe says that it should be written to myServer.exe instead.
And GCC will then ignore the first output file name.
Solution: remove the - from the library name.
I had similar problem as you when I made the CMake build with BUILD_SHARED_LIBS on.
For me it was working when I installed open62541 with CMake options UA_ENABLE_AMALGAMATION on and UA_NAMESPACE_ZERO full (rest default)
I compiled with the command
gcc -std=c99 myserver.c open62541.c -o server -lws2_32
Inside the selected folder are just the files open62541.c/.h and myserver.c

Mingw32 make command: Unrecognized option -z

I'm trying to make this project using Mingw32:
GitHub PNG2POS
For that, I'm doing the following command using git bash:
git clone --recursive https://github.com/petrkutalek/png2pos.git
It creates a folder called png2pos containing the project sources, and an important file called Makefile.
From there, I cd into the newly create folder, and try to execute the command
make
The expected result was the sources being built into an executable file, but I'm getting some errors that don't allow me to to that:
(...)/x86_64-pc-cygwin-bin/ld: unrecognized option '-z'
use the --help option for usage information
collect2: error: ld returned 1 exit status
Makefile:36: recipe for target 'png2pos' failed
mingw32-make: *** [png2pos] Error 1
What am I supposed to do for this to work and create my desired executable file?

C program files compiling with VIM on windows10

Is there anything that I need to configure in order that VIM on my Win10 machine compiles my C files?
As of this moment, VIM throws me into the DOS prompt with the following:
[No write since last change]
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot open output file a.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
shell returned 1
Press ENTER or type command to continue
Add the following to your _vimrc file
set makeprg=gcc\ -o\ %:r\ %\ -Wall
Also, add the bin directory of your gcc compiler to the path.

Resources