I wrote a Nim program,
echo("Hello.")
And then I tried to cross compile for a Linux machine,
nim c --cpu:i386 --os:linux -c hello.nim
This produced the following output:
config/nim.cfg(45, 2) Hint: added path: '/Users/connor/.babel/pkgs/' [Path]
config/nim.cfg(46, 2) Hint: added path: '/Users/connor/.nimble/pkgs/' [Path]
Hint: used config file '/usr/local/lib/nim-0.10.2/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: hello [Processing]
Hint: operation successful (8753 lines compiled; 0.140 sec total; 14.148MB)[SuccessX]
At this point I changed into the nimcache/ directory and tried to execute:
gcc hello.c -o hello.o
But that gave me an error:
hello.c:5:10: fatal error: 'nimbase.h' file not found
#include "nimbase.h"
^
1 error generated.
I thought, "no biggie, I'll just find nimbase.h and drop it in the nimcache directory there," but after that I got a new error,
In file included from hello.c:5:
./nimbase.h:385:28: error: 'assert_numbits' declared as an array with a
negative size
...sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
I'm not sure what I'm supposed to do with that. I had tried to use the --genScript option, but that resulted in similar errors. I'm running OS X Yosemite.
Thanks!
Update:
I wasn't sure how many architectures were supported for the --cpu: option, but I found a (partial?) list on the What makes Nim practical blog post. I ended up calling,
nim c --cpu:amd64 --os:linux -c hello.nim
This prevented the error I saw when compiling on my Linux box. If you're using Linux or OS X not sure what your CPU architecture is you can call,
less /proc/cpuinfo
The last problem is because you're running gcc for x86_64 arch, while the sources were generated for i386 arch.
I was having the same issue getting nim to compile executables for Windows, from a GNU/Linux machine, so I made a bash script. It takes the path to the directory containing *.nim source files and the name of the executable file to output.
I'm sure you could swap out the GCC compiler (MinGW in this case) and change the --os: switch as appropriate:
#!/usr/bin/env bash
# Nim must generate C sources only, to be fed to MingW
nim c --cpu:amd64 --os:windows --opt:speed --embedsrc --threads:on --checks:on -c -d:release $1/*.nim
# Copy nimbase.h so MingW32 can find it during compilation and linking
cp /opt/Nim/lib/nimbase.h $1/nimcache/nimbase.h
mkdir -p $1/bin
cd $1/nimcache && x86_64-w64-mingw32-gcc -save-temps $1/nimcache/*.c -o $1/bin/$2.exe
rm $1/nimcache/*.{i,s} # only care about *.o objects
ls -lAhF $1/nimcache
ls -lAhF $1/bin
Related
I'm trying to build a BLAS shared library for use with ghostjat/np cannot get make to run successfully on the CBLAS source code. I performed these exact steps on an Ubuntu 20 workstation:
# create new directory
mkdir ~/blas
cd ~/blas
# fetch and extract the CBLAS source code linked from the BLAS page
wget http://www.netlib.org/blas/blast-forum/cblas.tgz
tar -xvzf cblas.tgz
#cd into the CBLAS dir
cd CBLAS
#get appropriate make file according to README:
rm Makefile.in
ln -s Makefile.LINUX Makefile.in
#then we try make
make
This results in an error because gfortran was not installed:
gfortran -O3 -c sdotsub.f
make[1]: gfortran: Command not found
make[1]: *** [Makefile:247: sdotsub.o] Error 127
make[1]: Leaving directory '/home/foo/biz/machine-learning/blas/CBLAS/src'
make: *** [Makefile:147: allprecision] Error 2
So I install gfortran
sudo apt install gfortran
# answer YES to prompts
I am then able to make most of the project, but it croaks with an error:
make[1]: Entering directory '/home/foo/biz/machine-learning/blas/CBLAS/testing'
gcc -I../include -O3 -DADD_ -c c_sblas1.c
gfortran -O3 -c c_sblat1.f
c_sblat1.f:214:48:
214 | CALL STEST1(SNRM2TEST(N,SX,INCX),STEMP,STEMP,SFAC)
| 1
Warning: Rank mismatch in argument ‘strue1’ at (1) (scalar and rank-1) [-Wargument-mismatch]
c_sblat1.f:218:48:
218 | CALL STEST1(SASUMTEST(N,SX,INCX),STEMP,STEMP,SFAC)
| 1
Warning: Rank mismatch in argument ‘strue1’ at (1) (scalar and rank-1) [-Wargument-mismatch]
gfortran -o xscblat1 c_sblat1.o c_sblas1.o ../lib/cblas_LINUX.a libblas.a
gfortran: error: libblas.a: No such file or directory
make[1]: *** [Makefile:72: xscblat1] Error 1
make[1]: Leaving directory '/home/foo/biz/machine-learning/blas/CBLAS/testing'
make: *** [Makefile:180: alltst] Error 2
What is the problem here? This is mostly greek to me, but it looks like it compiles successfully all the CBLAS source code except it seems to barf when it gets to the testing, complaining that it cannot find a file, libblas.a. Can someone help me make sure this make operation completes?
Also, I was expecting this compilation step to produce a shared library, perhaps cblas.so or something. I am hoping this process will yield a viable BLAS library that I can use with ghostjat/np to perform fast matrix operations from a PHP script. However, there are no files in this directory ending in .so. Should I be looking for some other file?
EDIT: the comments have suggested that perhaps I should 'install BLAS' or 'install the libopenblas-dev package' on this machine. Let me first say that my goal is to obtain a library that I might distribute with some PHP source code. I am under the impression that building/making CBLAS will provide this library.
EDIT 2: After attempting a lot of trial and error, I think (but am not sure) that CBLAS is not a full-blown implementation of the BLAS functionality, but just a C wrapper around the BLAS functions, which are written in FORTRAN. It would appear that the makefile in CBLAS must be changed to point to a BLAS static library. I've been able to build the BLAS 3.11.0 library like so:
cd ~/blas
curl https://netlib.org/blas/blas-3.11.0.tgz > blas-3.11.0.tgz
tar -xvzf blas-3.11.0.tgz
cd BLAS-3.11.0
make
this runs for about a minute or so and yields a static lib, blas_LINUX.a. I take note of this file's location:
/Users/foo/Desktop/biz/machine-learning/blas2/BLAS-3.11.0/blas_LINUX.a.
I then return to my previously downloaded/extracted CBLAS folder:
cd ~/blas/CBLAS
and note this information in the README file:
BLLIB is your Legacy BLAS library
I edit this line in Makefile.in:
BLLIB = libblas.a
so that it refers instead to the static blas_LINUX. I just compiled above:
BLLIB = /Users/foo/Desktop/biz/machine-learning/blas2/BLAS-3.11.0/blas_LINUX.a
I save the make file and then make CBLAS:
make clean all
This runs for awhile, but fails in the testing phase with a certain gfortrain complaint:
( cd testing && make all )
gcc -I../include -O3 -DADD_ -c c_sblas1.c
gfortran -O3 -c c_sblat1.f
c_sblat1.f:214:48:
214 | CALL STEST1(SNRM2TEST(N,SX,INCX),STEMP,STEMP,SFAC)
| 1
Error: Rank mismatch in argument 'strue1' at (1) (scalar and rank-1)
c_sblat1.f:218:48:
218 | CALL STEST1(SASUMTEST(N,SX,INCX),STEMP,STEMP,SFAC)
| 1
Error: Rank mismatch in argument 'strue1' at (1) (scalar and rank-1)
make[1]: *** [c_sblat1.o] Error 1
make: *** [alltst] Error 2
Not a direct answer, but since you're on Ubuntu you can just install the libopenblas-dev package which contains the cblas headers and will pull in a high performance BLAS library as a dependency.
I stumbled across these directions which have worked for me, at least on Ubuntu 20.04. A couple of things changed so I list the exact steps I took here on my Ubuntu 20.04 workstation. The basic solution is to first compile BLAS (this appears to be FORTRAIN code) into a static library, blas_LINUX.a, and then modify the CBLAS files to point to that static library. There are tgz archives for both on the BLAS homepage.
# make a working dir
mkdir ~/cblas
cd ~/cblas
# fetch the BLAS library (not CBLAS, just BLA)S
wget http://www.netlib.org/blas/blas-3.11.0.tgz
tar -xvzf blas-3.11.0.tgz
cd BLAS-3.11.0
make
This will produce a file, blas_LINUX.a. Take note of its location here, you'll need to refer to it in the CBLAS make file. Next, fetch CBLAS and compile.
# get out of this directory back to our working dir
cd ..
# fetch CBLAS tgz, linked from netlib page
wget http://www.netlib.org/blas/blast-forum/cblas.tgz
# extract it
tar -cvzf cblas.tgz
# cd into CBLAS dir for edits
cd CBLAS
# remove default makefile
rm Makefile.in
# copy LINUX make file to Makefile.in
ln -s Makefile.LINUX Makefile.in
# edit Makefile.in
nano Makefile.in
Make the following changes:
# path to just-compiled static lib
# NOTE your path will be different
BLLIB = /home/sneakyimp/cblas/BLAS-3.11.0/blas_LINUX.a
CBLIB = ../lib/cblas_$(PLAT).so
CFLAGS = -O3 -DADD_ -fPIC
FFLAGS = -O3 -fPIC
ARCH = gcc
ARCHFLAGS = -shared -o
Save & close Makefile.in and then make CBLAS
# this takes a bit of time
make
# ls -al lib
You should now have your so file in lib/cblas_LINUX.so
I was able edit the blas.h file in a composer-installed ghostjat/np to point to this cblas_LINUX.so file, and eventually get it working, but you'll have complaints about various functions in the that blas.h file which are not defined in CBLAS. If you remove each of the functions it complains about you may get it to work or not. I was able to get it working on Ubuntu 20 running php 8.2, but have had trouble on other machines. My attempt to run cblas_dgemm on a matrix i defined resulted in this error:
php: symbol lookup error: /home/sneakyimp/cblas/CBLAS/lib/cblas_LINUX.so: undefined symbol: dgemm_
To compile a string matching tool SMART in windows command, implemented in C programming language, the instruction was (in the the instruction set, after extracting the zip files):
how to compile smart source code:
makefile is the bash file used for compiling the C source files of the tool. Run the command ./makefile in order to compile the smart
tool. The code of each string matching algorithm is compiled an
tested separately.
The makefile contains the follwoing code:
#!/bin/bash
./logo
echo " Compiling smart.c..................................[OK]"
gcc source/smart.c -O3 -msse2 -o smart -lm
echo " Compiling show.c...................................[OK]"
gcc source/show.c -O3 -msse2 -o show
echo " Compiling selectAlgo.c.............................[OK]"
gcc source/selectAlgo.c -O3 -o select
echo " Compiling test.c...................................[OK]"
gcc source/test.c -O3 -o test
echo " Compiling all string matching algorithms..........."
gcc source/compilesm.c -o compilesm
./compilesm
echo " "
echo " "
It appears to be written to work on a POSIX system, such as GNU/Linux or macOS. I want to compile it on Windows. So, I did the following:
Installed Git-2.37.1-64-bit.exe and opened Git Bash
Executed command: cd C:/Users/DIMITRI/Downloads/smart-13.03
Executed command: ./makefile
But I got the following error:
source/smart.c:44:10: fatal error: sys/ipc.h: No such file or directory
The problem is that I am trying to use the Linux API on Windows. This error will occur for #include <sys/shm.h> also.
Is it possible to overcome this missing header-file problem (these files can not be included in Windows) by using different compiler (I have, x86_64-posix-seh-rev0, Built by MinGW-W64 project, 8.1.0) or installing another system on Windows (without installing Linux or other complicated, heavy system)?
Generally, is there a way to compile C source files written for POSIX system on Windows?
Thanks.
EDIT:
According to one suggestion of one member, I have tried Cygwin, got the same error.
I am trying to compile the gjh solver - written in C - into an executable file in windows. It is available on netlib
I downloaded the c file and am using gcc compiler via WinGW on windows' command prompt. Trying to compile the gjh.c file directly gave me an error that says:
gjh.c:33:21: fatal error: getstub.h: No such file or directory
#include "getstub.h"
compilation terminated.
I assumed that compiling gjh.c requires the dependency getstub.h.
getstub.h is not the only dependency required, there are other dependencies, namely: arith.h, asl.h, funcadd.h, and stdio1.h. All of these files are available on the same link where I found getstub.h. However, arith.h0 and stdio1.h0 are available instead of arith.h and stdio1.h.
Are these files the same? I tried to rename the .h0 files to .h and tried to compile gjh.c, but I got this error:
collect2.exe: error: ld returned 1 exit status
Are the two files the same? If not, is there any way for me to compile the gjh solver successfully into an .exe?
If that's the only problem in compiling, try using the -I switch in gcc:
gcc -I/my/path/to/include/files -o gjh gjh.c
the -I switch hints to gcc where to find your #include files.
I am not sure about the stdio1.h. I think your approach to rename is OK but that reference to external functions such as Sprintf. You need to link with a library defining that. If you know where it comes from, use the -L and -l switch in gcc for that:
gcc -I/my/path/to/include/files -L/my/path/to/library -lnameoflibrary \
-o gjh gjh.c
I'm attempting to use a C library for an opencourseware course from Harvard. The instructor's instructions for setting up the external lib can be found here.
I am following the instructions specific to ubuntu as I am trying to use this lib on my ubuntu box. I followed the instructions on the page to set it up, but when I run a simple helloWorld.c program using a cs50 library function, gcc doesn't want to play along.
Example:
helloWorld.c
#include <stdio.h>
#include <cs50.h>
int
main(void){
printf("What do you want to say to the world?\n");
string message = GetString();
printf("%s!\n\n", message);
}
$ gcc helloWorld.c
/tmp/ccYilBgA.o: In function `main':
helloWorld.c:(.text+0x16): undefined reference to `GetString'
collect2: ld returned 1 exit status
I followed the instructions to the letter as stated in the instructions, but they didn't work for me. I'm runing ubuntu 12.04. Please let me know if I can clarify further my problem.
First, as a beginner, you should always ask GCC to compile with all warnings and debugging information enabled, i.e. gcc -Wall -g. But at some time read How to invoke gcc. Use a good source code editor (such as GNU emacs or vim or gedit, etc...) to edit your C source code, but be able to compile your program on the command line (so don't always use a sophisticated IDE hiding important compilation details from you).
Then you are probably missing some Harvard specific library, some options like -L followed by a library directory, then -l glued to the library name. So you might need gcc -Wall -g -lcs50 (replace cs50 by the appropriate name) and you might need some -Lsome-dir
Notice that the order of program arguments to gcc is significant. As a general rule, if a depends upon b you should put a before b; more specifically I suggest
Start with the gcc program name; add the C standard level eg -std=c99 if wanted
Put compiler warning, debugging (or optimizing) options, eg -Wall -g (you may even want to add -Wextra to get even more warnings).
Put the preprocessor's defines and include directory e.g. -DONE=1 and -Imy-include-dir/
Put your C source file hello.c
Put any object files with which you are linking i.e. bar.o
Put the library directories -Lmy-lib-dir/ if relevant
Pur the library names -laa and -lbb (when the libaa.so depends upon libbb.so, in that order)
End with -o your-program-name to give the name of the produced binary. Don't use the default name a.out
Directory giving options -I (for preprocessor includes) and -L for libraries can be given several times, order is significant (search order).
Very quickly you'll want to use build automation tools like GNU make (perhaps with the help of remake on Linux)
Learn also to use the debugger gdb.
Get the habit to always ask for warnings from the compiler, and always improve your program till you get no warnings: the compiler is your friend, it is helping you!
Read also How to debug small programs and the famous SICP (which teaches very important concepts; you might want to use guile on Linux while reading it, see http://norvig.com/21-days.html for more). Be also aware of tools like valgrind
Have fun.
I take this course and sometimes I need to practice offline while I am traveling or commuting. Under Windows using MinGW and Notepad++ as an IDE (because I love it and use it usually while codding python) I finally found a solution and some time to write it down.
Starting from scratch. Steps for setting up gcc C compiler, if already set please skip to 5
Download Git and install. It includes Git Bash, which is MINGW64 linux terminal. I prefer to use Git as I need linux tools such as sed, awk, pull, push on my Windows and can replace Guthub's terminal.
Once Git installed make sure that gcc packages are installed. You can use my configuration for reference...
Make sure your compiler works. Throw it this simple code,
by saving it in your working directory Documents/Harvard_CS50/Week2/
hello.c
#include <stdio.h>
int main(void)
{
printf("Hello StackOverflow\n");
}
start Git Bash -> navigate to working directory
cd Documents/Harvard_CS50/Week2/
compile it in bash terminal
gcc helloworld.c -o helloworld.exe
execute it using bash terminal
./helloworld.exe
Hello StackOverflow
If you see Hello StackOverflow, your compiler works and you can write C code.
Now to the important bit, installing CS50 library locally and using it offline. This should be applicable for any other libraries introduced later in the course.
Download latest source code file cs50.c and header file cs50.h from https://github.com/cs50/libcs50/tree/develop/src and save them in Documents/Harvard_CS50/src
Navigate into src directory and list the files to make sure you are on the right location using
ls
cs50.c cs50.h
Cool, we are here. Now we need to compile object file for the library using
gcc -c -ggdb -std=c99 cs50.c -o cs50.o
Now using the generated cs50.o object file we can create our cs50 library archive file.
ar rcs libcs50.a cs50.o
After all this steps we ended with 2 additional files to our original files. We are interested in only 2 of them cs50.h libcs50.a
ls
cs50.c cs50.h cs50.o libcs50.a
Copy Library and header files to their target locations. My MinGW is installed in C:\ so I copy them there
cs50.h --> C:\MinGW\include
libcs50.a --> C:\MinGW\lib
Testing the cs50 Library
To make sure our library works, we can throw one of the example scripts in the lecture and see if we can compile it using cs50.h header file for the get_string() method.
#include <stdio.h>
#include <cs50.h>
int main(void)
{
printf("Please input a string to count how long it is: ");
string s = get_string();
int n = 0;
while (s[n] != '\0')
{
n++;
}
printf("Your string is %i chars long\n", n);
}
Compile cs50 code using gcc and cs50 library. I want to be explicit and use:
gcc -ggdb -std=c99 -Wall -Werror test.c -lcs50 -o test.exe
But you can simply point the source, output filename and cs50 library
gcc test.c -o test.exe -lcs50
Here we go, program is compiled using header and methods can be used within.
If you want Notepad++ as an IDE you can follow this tip to set it up with gcc as a compiler and run your code from there.
Just make sure your nppexec script includes the cs50 library
npp_save
gcc -ggdb -std=c99 -Wall -Werror "$(FULL_CURRENT_PATH)" -lcs50 -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe"
cmd /c "$(CURRENT_DIRECTORY)\$(NAME_PART).exe"
Download the cs50 from: http://mirror.cs50.net/library50/c/library50-c-5.zip
Extract it. (You will get two files cs50.c and cs50.h)
Now copy both the files to your default library folder. (which includes your stdio.h file)
Now while writing your program use: #include < cs50.c >
You can also copy the files to the folder containing your helloWorld.c file.
You have to use: #include " cs50.c ".
OR =====================================================================>
Open cs50.c and cs50.h files in text editor.
In cs50.h, just below #include < stdlib.h > add #include < stdio.h > and #include < string.h > both on new line.
Now open cs50.c file, copy everything (from: /**Reads a line of text from standard input and returns the equivalent {from line 47 to last}) and paste it in cs50.h just above the #endif and save the files.
Now you can copy the file cs50.h to either your default library folder or to your current working folder.
If you copied the file to default folder then use: #include < cs50.h > and if you copied the files to current working folder then use: #include " cs50.h ".
You need to link against the library during compilation. The library should end in .a or .so if you are on Ubuntu. To link against a library:
gcc -o myProgram myProgram.c -l(library name goes here but no parentheses)
You have to link against the library, how come GCC would know what library you want to use?
gcc helloWorld.c -lcs50
Research Sources:
building on the answers above given by Basile Starynkevitch, and Gunay Anach
combined with instructions from some videos on youtube 1 2
Approach:
covering the minimum things to do, and sharing the "norms" separately
avoiding any modification to anywhere else on the system
including the basic breakdown of the commands used
not including all the fine details, covering only the requirements absolute to task or for effective communication of instructions. leaving the other mundane details to the reader
assuming that the other stuff like compiler, environment variable etc is already setup, and familiarity with shell's file navigation commands is there
My Environment:
compiler: gcc via msys2
shell: bash via msys2
IDE: doesnt matter here
Plan:
getting the source files
building the required files: *.o (object) and *.a (archive)
telling the compiler to use it
Action:
Let's say, current directory = "desktop/cs50"
It contains all the *.c files like test-file.c which I will be creating for assignments/problem sets/practise etc.
Get the *.h and *.c files
Source in this particular case: https://github.com/cs50/libcs50/tree/main/src
Go over each file individually
Copy all the content of it
Say using "Copy raw contents" icon of individual files
Create the corresponding file locally in the computer
Do it in a a separate folder just to keep things clean, let's say in "desktop/cs50/src" aka ./src
Build the required files using in the terminal after changing your current directory to "desktop/cs50/src" :
gcc -c cs50.c to create the "cs50.o" object file from "cs50.c" using "gcc"
ar cr libcs50.a cs50.o to create "libcs50.a" archive file which'll be containing "cs50.o" object file
Here, "libcs50" = "lib" prefix + "cs50" name (same as the header file's name)
This is the norm/standard way where the prefix "lib" is significant as well for a later step
However, prefix can be skipped, and it's not compulsory for name to match the header file's name either. Though, Skipping prefix is not recommended. And I can't say for sure about the name part
To tell the compiler to be able to use this infrastructure, the commands will be in following syntax after going to the parent directory (i.e. to "desktop/cs50"):
gcc test-file.c -Isrc -Lsrc -lcs50 if you used "lib" prefix in step 2.2 above
here, -I flag is for specifying the directory of *.h header file included in your test_file.c
and -L flag is for specifying the directory to be used for -l
and -l is for the name of the *.a file. Here the "lib" prefix talked about earlier, and ".a" extension is not mentioned
the order of these flags matter, keep the -I -L -l flags after the "test-file.c"
Some more notees:
don't forget to use the additional common flags (like those suggested above for errors etc)
if you skipped the "lib" prefix, then you can't use -L -l flags
so, syntax for command will become: gcc test-file.c -Isrc src/libcs50.a
say i created my test-file.c file in "desktop/cs50/psets", so, it can be handled in 2 notable ways (current dir = "desktop/cs50/") :
cd psets then changing the relative address correspondingly in -I -L, so result:
gcc test-file.c -I../src -L../src -lcs50
keeping current directory same, but then changing the file's relative address correspondingly, so result:
gcc psests/test-file.c -Isrc -Lsrc -lcs50
or use absolute addresses 😜
as it can be seen that this becomes quite long, that's when build automation tools such as make kick in (though i am accomplishing that using a shell script 😜)
I need to compile a program in MS DOS. I have Borland Editor, I can compile it using Alt+F9 but the things is what it do at the backend. I want to compile it in MS DOS. I m trying this:
c:\tc\bin>tcc -o hello.exe hello.c
where hello.c is is my file, hello.exe the file I want to produce. Its not working, what shouldI do? and also please tell me also how do I compile .cpp file manually from MS DOS.
If I remember correctly, Borland/Turbo C compiler's command line options didn't look like gcc options. You should try tcc /? for a command line help.
Turbo C++ Version 3.00 Copyright (c) 1992 Borland International
Syntax is: TCC [ options ] file[s] * = default; -x- = turn switch x off
-1 80186/286 Instructions -2 80286 Protected Mode Inst.
-Ax Disable extensions -B Compile via assembly
-C Allow nested comments -Dxxx Define macro
-Exxx Alternate Assembler name -G Generate for speed
-Ixxx Include files directory -K Default char is unsigned
-Lxxx Libraries directory -M Generate link map
-N Check stack overflow -O Optimize jumps
-P Force C++ compile -Qxxx Memory usage control
-S Produce assembly output -Txxx Set assembler option
-Uxxx Undefine macro -Vx Virtual table control
-X Suppress autodep. output -Yx Overlay control
-Z Suppress register reloads -a Generate word alignment
-b * Treat enums as integers -c Compile only
-d Merge duplicate strings -exxx Executable file name
-fxx Floating point options -gN Stop after N warnings
-iN Max. identifier length -jN Stop after N errors
-k Standard stack frame -lx Set linker option
-mx Set Memory Model -nxxx Output file directory
-oxxx Object file name -p Pascal calls
-r * Register variables -u * Underscores on externs
-v Source level debugging -wxxx Warning control
-y Produce line number info -zxxx Set segment names
C:\TC\BIN>
So, I think you should type:
tcc hello.c for C programs and tcc -P hello.cpp for C++ programs.
I belive this things must work
c:\tc\bin\tcc -c File.c \\ To generate objective file
c:\tc\bin\tcc -o File.obj \\ To generate exe from obj and please use .obj and not .o
c:\tc\bin\ tcc -run File.c \\ to generate exe file without .obj file
c:\tc\bin\File.exe \\ to run the exe file
I dont know why the
tcc -o good.exe File.obj \\not working, the error is good.exe file not found
I think we cant give a name to .exe file in tcc command line prompt.but its possible in gcc. I dont know about TCC much. If i find it i will let you know it !
Just take a look at these http://bellard.org/tcc/tcc-doc.html#SEC3. This is what I found on google . and googling makes you more powerful so keep on googling the things when you dont know .
Thanks
Further to Prof Falken's answer
tcc file.c <-- will compile in C
tcc file.cpp <-- will compile in cpp
tcc file.ext where .ext is anything other than cpp, will compile in C Unless --P is used then cpp is used to compile it, in which case .cpp is used, even if the extension is .c
I am running TCC in a VM and can't copy/paste from there here. But your test should find the same result as mine, if not, then perhaps I erred, but you can test for yourself given this code that works in C and not CPP, and code that works in CPP and not C. You can then experiment with changing the extension, and using -P or not.
The following code works in C only
conly.c
(A C++ expert told me re the following example, works in C and not C++, because C allows void* -> T* conversions. C++ does not)
#include <stdio.h>
#include <stdlib.h>
void main() {int *x=malloc(4);}
The following code works in C++ only
cpponly.cpp
#include <stdio.h>
void main() {
int a=9;
int& b=a;
printf("b=%d",b);
}