Error: undefinedreferenceto & #39; xxx) & #39; collect

Source: Internet
Author: User
Author: Jin Liang (golden1314521@gmail.com) csdn blog: blog. csdn. when netu012176591 compiles a dynamic link library, the following error occurs: error: undefinedreferencetoxxx) collect2: ldreturned1exitstatus attribute 1. i'm sure there is no difference between this and the Java file that calls the dynamic library.

Author: Jin Liang (golden1314521@gmail.com) csdn blog: http://blog.csdn.net/u012176591 compiled dynamic link library, the error: undefined reference to 'xxx) 'collect2: ld returned 1 exit status attribute 1. i'm sure there is no difference between this and the Java file that calls the dynamic library.

Author: Jin Liang (golden1314521@gmail.com) csdn blog: http://blog.csdn.net/u012176591

When compiling a dynamic link library, the following error occurs:

Error: undefined reference to 'xxx) 'collect2: ld returned 1 exit status

Attribute 1.

I am sure this has nothing to do with the Java file that calls the dynamic library, because it is also an error that I delete the Java file and re-compile it.

Attribute 2.

I'm sure this is not because I didn't include the header file to be used, and I tried to comment out the header file of another function. The error is:

Error: 'xxxxx' was not declared in this scope

Attribute 3.

When I change the function name to make it different from the previous name, an error is also prompted:

Error: 'xxxxx' was not declared in this scope

Attribute 4.

Even if I write this function directly into the file to call it, it is still such an error.

Attribute 5.

It is determined that it is not a problem with the Android. mk file.


Under what circumstances will the error "error: undefined reference to 'xxx) 'collect2: ld returned 1 exit status" be generated? I don't understand why this function is so special, but it has such an error.

When this function is clearly defined, the error "error: undefined reference to" occurs? Strange

Solution 1.

This solution is described as follows:

Add LOCAL_ALLOW_UNDEFINED_SYMBOLS: = true to android. mk.

That is, the compiler ignores a function that cannot be found.

I want to write this function, but I want it to work. You ignore it. Although it passes through the compilation process, can I still not find it when I call this function? I 'd better delete this function directly.

Solution 2.

After careful check and elimination, I finally found the problem. Restore the error message again.

In function render:/BitmapPlayerActivity. cpp: 35: error: undefined reference to 'brightnessfilter (unsigned short *, long, unsigned char )'
Collect2: ld returned 1 exit status
Make.exe: *** [obj/local/armeabi/libAVIPlayer. so] Error 1

At the same time, the file BitmapPlayerActivity. cpp of the function where the error occurs is pasted:

# Ifdef _ ARM_NEON _ void BrightnessFilter (unsigned short * pixels, long count, unsigned char brightness) {// ignore specific content} static void neonBrightnessFilter (unsigned short * pixels, long count, unsigned char brightness) {// ignore specific content} # endif

Do you see the problem? Note the macros of rows 1 and 17 # ifdef _ ARM_NEON _ and # endif, they are used together to compile the code between them based on whether or not the Variable _ ARM_NEON _ was defined. No, in this project, _ ARM_NEON _ was not defined, therefore, the BrightnessFilter (unsigned short *, long, unsigned char) function is not compiled, so the error: undefined reference error occurs.

PS1.

Note that if there is a call relationship between functions in the same cpp file, you must write the called function before the function to be called, for example, the following error is prompted during file Compilation:

Jni/BrightnessFilter. cpp: In function 'void BrightnessFilter (short unsigned int *, long int, unsigned char )':
Jni/BrightnessFilter. cpp: 7: 52: error: 'genericbrightnessfilter' was not declared in this scope
Make.exe: *** [obj/local/armeabi/objs/AVIPlayer/BrightnessFilter. o] Error 1

BrightnessFilter. cpp:

# Include "BrightnessFilter. h "void BrightnessFilter (unsigned short * pixels, long count, unsigned char brightness) {genericBrightnessFilter (pixels, count, brightness); // The genericBrightnessFilter () is called, but the function callback () there is no implemented body before the BrightnessFilter () function, so an error occurs} static void genericBrightnessFilter (unsigned short * pixels, long count, unsigned char brightness) {// The function body does not reference other functions, content omitted}

PS2.

Jni/Android. mk: 11: *** commands commence before first target. Stop.
This is because LOCAL_SRC_FILES in Android. mk contains spaces after the Slash when loading the file. delete the file. Similar errors may also occur in another place. For details, refer to the problems, solutions, related files and the entire process of compiling ffmpeg in Android.

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.