Eclipse compiles successfully but still gives sema

2020-01-23 07:09发布

NOTE: it apparently is a recurrent question on StackOverflow, but - for what I have seen - either people never find a way or their solution does not work for me

The problem:

I am using Eclipse Juno ADT. Everything was working fine until I tried to update the NDK. I replaced my ndk folder (that was the ndk-r8d) by the new version (i.e. ndk-r8e) and, in my Paths and Symbols configuration, I changed the includes to go from g++ 4.6 to 4.7.

It seemed to break my index: I could compile my code, but Eclipse was giving semantic errors, exactly like in [1] and [2]. The errors mainly come from symbol used by OpenCV4Android, such as distance, pt, queryIdx and trainIdx.

When I tried to backup to my old configuration, the index was still broken! I cannot find a way to change this.


What I have tried

  • Clean up the project
  • Rebuild, refresh, and all the other options in the "Index" submenu (when "right-clicking" on the project)
  • Disable / enable the indexer in the preferences
  • Verify that symbols such as trainIdx only appear in my OpenCV4Android include in the Paths and Symbols section.
  • Change the order of my includes in the Paths and Symbols section. I basically tried to put the OpenCV include in the beginning and in the end.

Some observations

What is not working

I assume that it is the CDT index because of the following:

  • In command line, I can build my project using ndk-build clean and ndk-build.
  • When I start Eclipse, I have no error until I open a C++ file (from the jni folder).
  • I can always build the project, but as long as I have opened a C++ file, I can't run the application anymore because of a lot of Field '<name>' could not be resolved.
  • If I don't open the C++ files, Eclipse doesn't report any error and can build and deploy the Android application successfully.

Interesting fact

The following code reports errors on line, queryIdx, pt:

cv::line(mRgb, keypointsA[matches[i].queryIdx].pt, keypointsB[matches[i].trainIdx].pt, cv::Scalar(255, 0, 0, 255), 1, 8, 0);

If I write it as follows, it works:

cv::DMatch tmpMatch = matches[i];
cv::KeyPoint queryKp = keypointsA[tmpMatch.queryIdx];
cv::KeyPoint trainKp = keypointsB[tmpMatch.trainIdx];
cv::line(mRgb, queryKp.pt, trainKp.pt, cv::Scalar(255, 0, 0, 255), 1, 8, 0);

It is not that all of the OpenCV functions are unresolved: only pt, queryIdx and trainIdx are.

Any comment will be really appreciated.

8条回答
地球回转人心会变
2楼-- · 2020-01-23 08:05

In your selected project preferences within the Eclipse environment, go to C/C++ General -> Code Analysis -> Launching. Make sure that both check boxes are unchecked. Close and reopen the project or restart eclipse and rebuild the project.

查看更多
\"骚年 ilove
3楼-- · 2020-01-23 08:07

I had the same issue. I had all the proper include paths setup but after opening the .c/.cpp or .h file and it would start marking everything as "Unresolved."
This worked for me...
Go to:
PREFERENCES -> C/C++ -> INDEXER
Check Index Source And Header Files Open in Editor.

查看更多
登录 后发表回答