Reference issue not defined by GCC at compile time for ' xxxx '

Source: Internet
Author: User
Tags crc32 sha1

Reference issue not defined by GCC at compile time for ' xxxx '
    • Reference issue not defined by GCC at compile time for ' xxxx '
      • Reason
      • Solutions
        • GCC Dependency order problem

In the use of gcc compile time sometimes encounter such a problem, compile to .o (obj) file is not a problem, but compile (this step should be a link) for the executable file will appear when the definition of ' xxx ' is not found.

This article by Mob Lym fabricated, welcome reprintblog.cnblogs.net/oloroso
This article by Mob Lym fabricated, welcome reprintmy.oschina.net/oloroso

For example:

g++ -o spider   -rdynamic -lpthread -levent -lcrypt -ldl bloomfilter.o confparser.o crc32.o dso.o hashs.o md5.o qstring.o sha1.o socket.o spider.o threads.o url.o...dso.o:在函数‘dso_load(char const*, char const*)’中:dso.cpp:(.text+0x3c):对‘dlopen’未定义的引用dso.cpp:(.text+0x4c):对‘dlsym’未定义的引用dso.cpp:(.text+0xb5):对‘dlerror’未定义的引用dso.cpp:(.text+0x13e):对‘dlclose’未定义的引用
Reason

This occurs because the main reason is that C + + is compiled into a obj file without the need for a specific implementation of the function, as long as the function of the prototype. However, when linking to an executable file, it must be implemented specifically. If the error is that the 未声明的引用 prototype of the function is not found, the solution is not detailed here, usually the related header file is not included.

Solutions

Specify the reason is good to do, since the knowledge is missing the specific implementation of the function, then give it the implementation of this function is good. For example above, because of the fact that,,, dlopen dlsym dlerror dlclose These functions are implemented, these functions are used to load the dynamic link library, compile time need to add -ldl to use the dl library (this is a static library, in the system directory, /usr/lib/i386-linux-gnu/libdl.a /usr/lib/x86_64-linux-gnu/libdl.a ).

But look at the compile time there are add -ldl options, then why not?

GCC Dependency order problem

The main reason for this is that gcc when compiling, the individual files are dependent on the order of the problem.

At gcc compile time, if the file a depends on the file b , then the compilation must be put in a front, b put the back.

For example main.c , when you use pthread library-related functions in, the compilation must be main.c before and -lpthread after. gcc main.c -lpthread -o a.out.

The problem is that the order in which the libraries are introduced is in the front, and they are placed in the back.

g++ -o spider  bloomfilter.o confparser.o crc32.o dso.o hashs.o md5.o qstring.o sha1.o socket.o spider.o threads.o url.o    -rdynamic -lpthread -levent -lcrypt -ldl

Reference issue not defined by GCC at compile time for ' xxxx '

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.