Member declaration not found - c++

I have worked on a C++ project using a regular text editor. Later, I imported all the files to Eclipse to make it debugging easier.
In Eclipse a weird thing happens. It complains "Member declaration not found" even if I have included the header file. The header file has the function definition.
How do I fix this problem?

"Member declaration not found" is an error produced by the Eclipse static analysis tool (codan). If you get this error, but the compilation succeeds this is a false positive. Older versions of this tool are known to give some false positives, see for example this bug report. So I recommend updating Eclipse CDT to the most recent version.
Another thing that may cause this error is an unresolved include that prevents Eclipse from parsing a portion of your code correctly. Selecting Index -> Search For Unresolved Includes in the context menu of the project will give you the list of unresolved includes. See this answer for the details of how to fix it.
Here's an example:
class C {
void f(std::vector<int>&);
};
void C::f(std::vector<int>&) {} // Member declaration not found
The above example causes "Member declaration not found" error in Eclipse CDT even if you have <vector> included but unresolved (due to misconfigured include paths).

I also experienced this problem several times in Eclipse though building is successful. We can simply solve this problem by rebuild the C/C++ index in project menu. :)

I got this problem in Eclipse, but building in terminal was successful. So I just rebuild the C/C++ index in Eclipse:
Right click on the project -> index -> rebuild.

I noticed that "Member declaration not found" will report also when you create a class with a name that is already used or is a a keyword.

I found an error in my .cpp file that creates this message. I had namespace std { in the front of the file, and I placed new functions that I was creating after the closing } for namespace. Moving the closing } to the end of the file so that the defined files were now in the namespace fixed the error message.
Example that creates the error.
#include "MyStrFuncs.h"
**namespace** std {
MyStrFuncs::MyStrFuncs() {
// TODO Auto-generated constructor stub
}
MyStrFuncs::~MyStrFuncs() {
// TODO Auto-generated destructor stub
}
} // This ends the **namespace**
//Additional functions will now generate the member declaration not found error...
int MyStrFuncs::str2i(string strIn) {
int results;
istringstream convert(strIn);
if( !(convert)>>results) results = 0;
return results;
}
// Fix by moving closing } for namespace to here. Good luck.

Even with the CDT 9.2.1 and Eclipse Neon 4.6.3 "Member declaration not found" problems are reported.
As answered by Srijeyanthan, the following should resolve it:
Project > C/C++ Index > Rebuild.

I also experienced this problem while splitting source and header files in eclipse.I resolved this by "implementing methods" eclipse instead of manual typing and building the project.By implementing methods "inline functions" will be added to source file.

Related

How do I avoid LNK2005 and LNK1169 errors while compiling TetGen in my project?

I am trying to compile TetGen and use the code below to tetrahedralize a .ply file although I am getting these two linker errors:
LNK2005 main already defined in tetgen.obj
LNK1169 one or more multiply defined symbols found
The files that are includes in my project solution are "tetgen.h", "predicates.cxx", and "tetgen.cxx", and the folder path that these three files are in is included in my Project Properties > C/C++ > General > Additional Include Directories. I did the same for the "monkey.ply" file as well.
This is all the code in my main file:
#include "tetgen.h"
int main()
{
tetgenio in, out;
in.firstnumber = 0;
in.load_ply((char *)"monkey.ply");
tetgenbehavior* b = new tetgenbehavior();
tetrahedralize(b, &in, &out);
}
Here are the "tetgen.h", "predicates.cxx", and "tetgen.cxx" files I'm using : https://minhaskamal.github.io/DownGit/#/home?url=https://github.com/libigl/tetgen
I researched these errors and looked around a great amount but can't see why this is occurring. Any help would be greatly appreciated.
LNK2005 main already defined in tetgen.obj
This message tries to tell you that your tetgen library contains the main function. Your "main file" also contains a main function. This is a conflict. You should remove your main function from your code, and read the documentation of the tetgen library on how to provide a replacement. Typically, libraries which define their own main functions require you to rename your main to have some other name, which the documentation should clearly specify.
#include "tetgen.h"
int main_replacement_called_by_tetgen()
{
...
}
For anyone who may have this issue in the future with TetGen: The problem was that the TETGEN_LIBRARY flag needed to be defined in tetgen.h. I knew this, but every time I defined the flag, it would cause memory errors without fail. So, I kept TETGEN_LIBRARY undefined to avoid the memory error. Turns out, with TETGEN_LIBRARY defined, it will work. The problem was that "monkey.ply" did not exist/was in the wrong folder. Because "monkey.ply" did not exist it threw an unhandled exception. Why TetGen does not have a simple handle to check if a file exists before it tries to load it or not is beyond me. But that fixed things.

Declaring a static pointer in class [duplicate]

While compiling on x64 plattform I am getting following error:
c:\codavs05\hpsw-sc\ovpacc\tools\codaaccesstest\coda_access.cpp(1572): fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\p2\sizeopt.c', line 55)
To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
------ Build started: Project: asyncexample, Configuration: Release Win32 ------
If I change settings to preprocessor file (Yes) i am not getting any error.
About my environment: Upgrading Microsoft Visual Studio 2005 to 2010
Please help.
I have had this problem with VS2015 while building locally in Windows.
In order to solve it, I deleted my build folder (Output Directory as seen in Properties/General) and rebuilt the project.
This always seems to help when strange things happen during the build.
I’ve encountered this error many times in VC++. Do the following steps. They’ve sometimes helped me with this issue:
Take a look at the exact location, pointed out by compiler error.
Find any external types or classes used there at that location.
Change the order of “include path” of those files found in step 2 and rebuild the solution.
I hope that help !!!!
I am getting same error with VC2012. Setting up the project properties Optimization to Disabled (/Od) resolved the issue.
In my solution, i've removed output dll file of the project, and I've made project rebuild.
I encountered the same error and spent quite a bit of time hunting for the problem. Finally I discovered that function that the error was pointing to had an infinite while loop. Fixed that and the error went away.
In my case was the use of a static lambda function with a QStringList argument. If I commented the regions where the QStringList was used the file compiled, otherwise the compiler reported the C1001 error. Changing the lambda function to non-static solved the problem (obviously other options could have been to use a global function within an anonymous namespace or a static private method of the class).
I got this error using boost library with VS2017. Cleaning the solution and rebuilding it, solved the problem.
I also had this problem while upgrading from VS2008 to VS2010.
To fix, I have to install a VS2008 patch (KB976656).
Maybe there is a similar patch for VS2005 ?
I got the same error, but with a different file referenced in the error message, on a VS 2015 / x64 / Win7 build. In my case the file was main.cpp. Fixing it for me was as easy as doing a rebuild all (and finding something else to do while the million plus lines of code got processed).
Update: it turns out the root cause is my hard drive is failing. After other symptoms prompted me to run chkdsk, I discovered that most of the bad sectors that were replaced were in .obj, .pdb, and other compiler-generated files.
I got this one with code during refactoring with a lack of care (and with templates, it case that was what made an ICE rather than a normal compile time error)
Simplified code:
void myFunction() {
using std::is_same_v;
for (auto i ...) {
myOtherFunction(..., i);
}
}
void myOtherFunction(..., size_t idx) {
// no statement using std::is_same_v;
if constexpr (is_same_v<T, char>) {
...
}
}
I had this error when I was compiling to a x64 target.
Changing to x86 let me compile the program.
Sometimes helps reordering the code. I had once this error in Visual Studio 2013 and this was only solved by reordering the members of the class (I had an enum member, few strings members and some more enum members of the same enum class. It only compiled after I've put the enum members first).
In my case, this was causing the problem:
std::count_if(data.cbegin(), data.cend(), [](const auto& el) { return el.t == t; });
Changing auto to the explicit type fixed the problem.
Had similar problem with Visual Studio 2017 after switching to C++17:
boost/mpl/aux_/preprocessed/plain/full_lambda.hpp(203): fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1518)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
Solved by using Visual Studio 2019.
I first encountered this problem when i was trying to allocate memory to a char* using new char['size']{'text'}, but removing the braces and the text between them solved my problem (just new char['size'];)
Another fix on Windows 10 if you have WSL installed is to disable LxssManager service and reboot the PC.

Visual Studio Intellisense + Resharper throws ambigous symbol error when including the same header twice

I am using Resharper C++ with visual studio and I am getting an ambigous symbol error due to an apparent namespace clash. I get this error in Sd.cpp when, for example, I want to instantiate an enum Mode.
The enum class Mode is defined in Pins.hpp, which is included in Sd.hpp. However if I include Pins.hpp in Sd.ccp the ambigous symbol error pop ups. There is no problem compiling the project.
Could Resharper / Intellisense be not recognizing that Pins.hpp is the same file? The way #pragma once works is by the file path, so I don't know how that would happen.
I recently changed the include directories, so maybe this has something to do with the issue.
Any help would be appreciated.
Sd.hpp
#include "Pins.hpp"
Sd.cpp
#include "Pins.hpp"
Mode mode; //error here, Mode is underlined
Pins.hpp
enum class Mode : uint32_t
{
AlternatePushPull = GPIO_MODE_AF_PP,
};
EDIT1: Added code.
EDIT2: Renamed question to something more usefull
Turns out ReSharper looks into the entire VS solution when linting, not solely the project. Since in my solution I had some project which included the same libraries, but from a different location. Therefore ReSharper could not resolve the names.
The solution was simple: make sure that all projects all include the same files.

Eclipse cannot resolve fields declared with macro

I've recently started diving into the code of an open source project, which is largely written in C++. I'm using Eclipse 3.8 in Ubuntu 12.10.
THE PROBLEM:
Eclipses is incorrectly flagging fields as unresolved because of a particularly elaborate convention used to separate field declarations out of the header files.
someclass.h
class SomeClass
{
public:
#define MACRO_CLASS_PARAM(Name) SomeType m_##Name;
#include "fields.h"
#undef MACRO_CLASS_PARAM
};
fields.h
MACRO_CLASS_PARAM(Field1)
MACRO_CLASS_PARAM(Field2)
...
Now in the cpp file, if I want to do something like instanceOfSomeClass.Field1 Eclipse will flag it as an error with "Field 'Field1' could not be resolved".
THE QUESTION: Is there any way to get Eclipse to correctly handle this situation?
The inability to correctly process #include statements that are not at global scope is a long-standing deficiency in Eclipse's indexer.
Things you could do about it:
Revise your code to avoid this pattern. Once the textual header inclusion model is superseded by C++ Modules, it's going to be invalid anyways.
Contribute a fix for this deficiency to Eclipse CDT.
Use a different IDE that can parse this pattern. (I don't know of one off the top of my head, but I also haven't spent a lot of time looking.)

What can cause ambiguous symbol errors on one computer and not another?

I'm using Visual Studio 2010 to work on C++ code. The project and all its contents have been written by someone else, and copied onto a shared drive. When the creator builds it on his computer, it works fine. When I try to build the solution, I get a whole bunch of these errors
error C2872: '<lambda0>' : ambiguous symbol could be
'[File].cpp(66) : anonymous-namespace'::<lambda0>' or
'[Different file].h(549) : `anonymous-namespace'::<lambda0>'.
Here's an example of a line which is said to be in error:
std::pair<int, std::pair<int, Point>> b) -> bool { return (a.second.second < b.second.second ); });
It seems like the error always occurs with a line which ends in '});'. The full code is rather enormous to show here, and it works on other computers, so presumably it's a problem with my settings or something. Can anybody hazard a guess as to what they may be?
Not sure if you've seen this or not but according to MSDN page for that compiler error:
C2872 can occur if a header file includes a using Directive (C++), and a subsequent header file is #include'd and contains a type that is also in the namespace specified in the using directive. Specify a using directive only after all your header files are specified with #include.
MSDN Page
I have had the same issue withe ambiguous symbol problem. For me, it turns out that I was using two namespaces which have the same function but obviously different definitions. I have to stop using one of the namespaces and this solve the issue.
As an example:
using namespace cv;
using namespace boost::accumulator;
accumulator_set<double, stats<tag::mean, tag::variance> > acc;
double meanval = mean (acc);
This will through a compilation error: error C2872: 'mean' : ambiguous symbol This is because both namespaces cv and boost::accumulator have the same function "mean"
I hope this helps
I have had the same issue
Installing VS2010 SP1 fixed the ambiguous anonymous-namespace'::<lambda0> issue for me. VS2010 without the SP1 has problems with lambdas.