Tuesday 15 July 2014

gcc - Writing first c program in vi editor in cygwin -


I am new to [extremely] programming and signin, thanks to being a patient. I am using a PDF of Michael Wine's C programming for the beginner and I am trying to enter and compile the first example.

Here is what I wrote:

  #include & lt; Stdio.h & gt; Main () {printf ("\ nHello World \ n"); }   

When I try to compile using GCC , I get two errors:

1) Usr / lib / gcc / I686-pc-cygwin / 3.4.4. / ... / bin / ld: new: file format not recognized; Treatment as Linked Script

2) [same path as above] / bin / LD: new: 11: Syntax error collect 2: LD has 1 exit position Returning

I am pretty sure the actual syntax used in vi is correct (this is directly from one example) and the GCC command is also correct. Do I miss a package or do I have a bad road for Sagvin? Anyone know what's going on with it?

For better or worse, GCC uses the file name you've used to find out Whether to do the operation - for example run compiler, assembler or linker or some combination. Since you named your source file new , GCC assumes that it is a compiled object and is trying to link it. Either rename new.c or -xc to compile while compiling.

For future reference, a good way to debug a strange business with GCC is to pass the compiler driver -v flag if you do this for your original command line You will see that it only invites the linker, except for the compilation phase. An example from my machine:

  $ gcc -v new -o new.exe Using the built-in glasses Goal: i686- Configured with Apple's darwin11: / private / var / tmp / llvmgcc42 / Llvmgcc42-2336.11 ~ 182 / src / configure --disable check --enable-werror prefix = / application / xcode.app / content /developer/usr/llvm-gcc-4.2 --mandir = / share / man --enable- Languages ​​= c, ObjC, c ++, ObjC ++ --program- prefix = llvm- --program - change name = / ^ [Coast Guard] [^ .-] * $ / s / $ / - 4.2 / - With-slibdir = / usr / lib --build = i686-apple darwin11 --enable-LLVM = / private / var / tmp /llvmgcc42/llvmgcc42-2336.11~182/dst-llvmCore/Developer/usr/local --program -ffects = i686- apple darwin11- --host = x86_64- apple Of darwin11 --target = i686- apple darwin11 - with - gxx - included - dir = / usr / included / c ++ / 4.2.1 thread model: POSIX GCC version 4.2.1 (built on the basis of Apple Inc. 5658 ) (LLVM 2336.11.00 builds) / usr / LLVM-gcc- 4.2 / bin /../ libexec/GCC/I686- apple of darwin11 / 4.2.1 / collect2 -dynamic -arch x86_64 -macosx_version_min 10.8.4 -weak_reference_mismatches Non Weak -o new.exe -lcrt1.10.6.o -L /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/x86_64 -L / Applications / Xcode. A pp / content / developer / usr / llvm-gcc-4.2 / lib / gcc / i686-apple's darwin11 / 4.2.1 / x86_64 L / usr / LLVM-gcc-4.2 / bin /../ lib / gcc / i686 Apple-darwin11 / 4.2.1 l / Usr / llv-gcc -4.2 / bin /../ lib / gcc l / application / xcode.app / content / developer / usr / llvm-gcc-4.2 / lib / gcc / i686-apple-darwin11 / 4.2.1 - L / usr / llvm-gcc-4.2 / bin /../ lib / gcc / i686-apple-darwin11 / 4.2.1 /../../ .. - L / Application / Xcode.app / Content / Developer / Usr / LLVM-GCC-4.2 / lib / gcc / i686-apple darwin11 / 4.2.1 /../..... New -lSystem -lgcc -lSystem ld: Warning: File new unseen, file unsupported file format Was created for (0x20 0x23 0x69 0x6e 0x63 0x6c 0x75 0x64 0x65 0x20 0x3c 0x73 0x74 0x64 0x69 0x6f) Architecture is not added (x86_64): architecture x86_64 A new undefined symbol: "_main", referenced from: start in crt1.10.6.o ld: symbol (s) architecture x86_64 not found for collect2: ld returned to exit position 1    

No comments:

Post a Comment