Getting LNK errors trying to compile from .asm file using ml.exe - masm

Here's my code:
#include <stdio.h>
int main(void) {
printf("Hello! \n");
return 0;
}
I call first cl /Fa test.c, then call ml test.asm and I get the errors:
LIBCMT.lib(default_local_stdio_options.obj) : error LNK2005:
___local_stdio_printf_options already defined in test.obj
libvcruntime.lib(undname.obj) : error LNK2005: ___local_stdio_printf_options already defined in test.obj
test.exe : fatal error LNK1169: one or more multiply defined symbols found
It works fine if I don't use printf. What am I doing wrong?

Related

1 I am doing the cs50 course and decided to run the code from there on my MacBook [duplicate]

This question already has an answer here:
CS50 get_string error linker command failed with exit code 1
(1 answer)
Closed 13 days ago.
I have the following code:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int x = get_int("whats x? ");
int y = get_int("whats y? ");
if (x < y)
{
printf("x is less than y\n");
}
}
It keeps giving me this error
moutarrjallow#Moutarrs-MBP cclang % make ccompare
cc ccompare.c -o ccompare
Undefined symbols for architecture x86_64:
"_get_int", referenced from:
_main in ccompare-91f0e5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ccompare] Error 1
You need to link with the cs50 library by adding the -lcs50 to above. In your Makefile you can probably do that by setting LDLIBS := -lcs50.

Compiling C and Fortran using iFort

I am trying to call a simple "Hello World" code from C using Fortran. When I compile using iFort, it is giving me "error LNK2019: unresolved external symbol HELLO referenced in function MAIN__"
C Code:
#include <stdio.h>
void hello_(){
printf("Hello World :) \n");
}
Fortran Code:
program Fortran_C_Link_Test
C
implicit None
C
call hello()
C
stop
end
How I Compiled:
cl -c c_src.c
to generate the c_src.obj object file
ifort -c fortran_src.f
to generate the fortran_src.obj object file
ifort -o program c_src.obj fortran_src.obj
to generate the executable

Compilation terminated while compiling in visual studio code

#include <stdio.h>
int main()
{
int a = 10, b = 15, c;
c = a + b;
printf("%d", c);
return 0;
}
Whenever I tried to compile it produce error
gcc.exe: error: instruction: No such file or directory
gcc.exe: error: Arthematic: No such file or directory
gcc.exe: error: declearation: No such file or directory
gcc.exe: fatal error: no input files
compilation terminated.
Error code image
Your shell command is malformed. You used
gcc instruction Arthematic declearation.c -o instruction Arthematic declearation
when you should have used
gcc "instruction Arthematic declearation.c" -o "instruction Arthematic declearation"
Try to avoid using spaces in your file or directory name. If any of it contains spaces, than you should put it between "" marks.

MinGW compilation says header files are missing, which package maybe missing?

This is the first gcc error on compilation, copying features.h from the web into the include folder for MinGW helped :
$ gcc -g hello_world.c
In file included from c:\mingw\include\stdio.h:55,
from hello_world.c:1:
c:\mingw\include\_mingw.h:174:10: fatal error: features.h: No such file or directory
#include <features.h>
^~~~~~~~~~~~
compilation terminated.
This is the new error :
$ gcc -g hello_world.c
In file included from c:\mingw\include\_mingw.h:174,
from c:\mingw\include\stdio.h:55,
from hello_world.c:1:
c:\mingw\include\features.h:406:10: fatal error: stdc-predef.h: No such file or directory
#include <stdc-predef.h>
^~~~~~~~~~~~~~~
compilation terminated.
The hello-world file :
#include <stdio.h> int main(int argc, const char *argv[]) {
/* I am C developer */
printf("Hello, Poftut! \n");
return ; }
C:\MinGW\bin\ is in PATH.Pretty sure I have missed some package installation.

How do I compile with external header file in sublime text in C?

I use one header named header.h in main.c.
The function test is announced in header.h and defined in test.c.
However, it says words below even though I use build system as C.
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
Undefined symbols for architecture x86_64:
"test(int)", referenced from:
_main in main-a4d82e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 0.6s with exit code 1]
[cmd: ['bash', '-c', 'g++ -Wall -std=c++11 -O2 \'/Users/hanlock/Documents/CODE/TEST/TEST/main.c\' -o \'/Users/hanlock/Documents/CODE/TEST/TEST/main\' && osascript -e \'tell application "Terminal" to activate do script " cd \\"/Users/hanlock/Documents/CODE/TEST/TEST\\" &&start_ms=$(ruby -e \\"puts (Time.now.to_f * 1000).to_i\\")&&clear&&\\"/Users/hanlock/Documents/CODE/TEST/TEST/main\\" &&elapsed_ms=$(($(ruby -e \\"puts (Time.now.to_f * 1000).to_i\\") - start_ms))&& read -p \\"Press Enter to exit($elapsed_ms ms).\\"&&exit"\'']]
[dir: /Users/hanlock/Documents/CODE/TEST/TEST]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
I've read similar questions about this in C++. However, it seems not working in my case.
So, here comes the problem. How can I use external header file with sublime in language C?
Here is the code:
main.c
#include <stdio.h>
#include "./Header.h"
int main(int argc, const char * argv[]) {
test(1);
return 0;
}
header.h
#ifndef Header_h
#define Header_h
int test(int);
#endif
test.c
#include <stdio.h>
int test(int i){
printf("%d\n",i);
return 0;
}
In test.c:
#include "header.h"
In your shell:
gcc -I [dir] test.c
This will include any external header named header.h located in dir.
I hope this answers your question.

Resources