The header file has been included in link. C. Why can't I use LD to identify Mian and printf?

Source: Internet
Author: User

Linker LD

// Link. c

# Include <stdio. h>

# Include <stdlib. h>

Int main ()

{

Printf ("% F \ n", square (0.3 ));

System ("pause ");

Return 0;

}

// Square. c

Double square (Double X)

{

Return x * X;

}

Directly use LD to link the target file, and the output is as follows:

D: \ c traps and defects \ test> LD link. O square. O-o rlink.exe
Link. O: link. c :(. Text + 0xa): Undefined reference to '_ main'
Link. O: link. c :(. Text + 0x30): Undefined reference to 'printf'

Use GCC to link the target file. The output is as follows:

D: \ c traps and defects \ test> GCC link. O square. O-o rlink.exe

  • The header file has been included in link. C. Why can't I use LD to identify Mian and printf?

By default, LD does not link any database.

When using the GCC link, GCC can automatically add some default links.

Use the -- verbose (-v) option of GCC to view the details of the compilation link.

We can see some of the default links of GCC, such

D: \ c traps and defects \ test> GCC link. O square. O-v-o rlink.exe
Using built-in specs.
Collect_gcc = gcc
Collect_lto_wrapper = F:/programes/mingw/bin/../libexec/GCC/mingw32/4.6.2/Lto-wrap
Per.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure -- enable-languages ages = C, C ++, Ada, Fortran, OBJ
C, obj-C ++ -- disable-sjlj-exceptions -- with-dwarf2 -- enable-shared -- enable-libgo
MP -- disable-win32-registry -- enable-libstdcxx-Debug -- enable-version-specific-R
Untime-Libs -- Build = mingw32 -- prefix =/mingw
Thread model: Win32
GCC version 4.6.2 (GCC)
Compiler_path = F:/programes/mingw/bin/../libexec/GCC/mingw32/4.6.2/; F:/programes/
Mingw/bin/../libexec/GCC/; F:/programes/mingw/bin/../lib/GCC/mingw32/4.6.2 /../../
../Mingw32/bin/
LIBRARY_PATH = F:/programes/mingw/bin/../lib/GCC/mingw32/4.6.2/; F:/programes/mingw
/Bin /.. /lib/GCC/; F:/programes/mingw/bin /.. /lib/GCC/mingw32/4.6.2 /.. /.. /.. /.. /min
Gw32/lib/; F:/programes/mingw/bin/../lib/GCC/mingw32/4.6.2 /../../../
Collect_gcc_options = '-v''-O' 'rlink.exe'-mtune = i386 ''-March = i386'
F:/programes/mingw/bin/../libexec/GCC/mingw32/4.6.2/collect2.exe-bdynamic-o r
Link.exe F:/programes/mingw/bin/../lib/GCC/mingw32/4.6.2/.../crt2.o F:/prog
Rames/mingw/bin/../lib/GCC/mingw32/4.6.2/crtbegin. O-lf:/programes/mingw/bin /../
LIB/GCC/mingw32/4.6.2-lf:/programes/mingw/bin/../lib/GCC-lf:/programes/mingw/B
In /.. /lib/GCC/mingw32/4.6.2 /.. /.. /.. /.. /mingw32/lib-lf:/programes/mingw/bin /../
LIB/GCC/mingw32/4.6.2/.../. Link. O square. O-lmingw32-lgcc_eh-lgcc-lmoldna
Me-lmingwex-lmsvcrt-ladvapi32-lshell32-luser32-lkernel32-lmingw32-lgcc_e
H-lgcc-lmoldname-lmingwex-lmsvcrt F:/programes/mingw/bin/../lib/GCC/mingw32/
4.6.2/crtend. o

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.