c++ eclipse wrong error interpretation - c++

I'm having a problem with eclipse C++. My project compiles and runs but eclipse (juno) keeps saying there are thousands of errors. For example there's a function SetRun in my code, and eclipse mentions this error: "called Invalid arguments 'Candidates are: void SetRun(?)'", whereas SetRun is of type static void SetRun (uint32_t run);
I have quite a lot of similar errors like that, where eclipse doesn't seem to understand the type of the function and puts a '?' instead.
I also have many errors like this: "symbol '*' could not be resolved."
I think this is all part of the same issue.
What can I do to make eclipse stop telling me about these errors?

I tried the proposed solution and it did not work for me. What helped was to turn off CodeAnalysis for the project. I went to Properties->C/C++ General->Code analysis. Selected Use Project Settings and turned off all errors. This is of course very annoying and unfortunate and I would be glad to know when it is properly fixed. It is a shame we can't get use of the feature any other decent IDE has.

Actually Eclipse is some kind of unstable project. Try to clean and refresh the project.

In Eclipse:
right click the project,
click properties
Expand "C/C++ general" the item in the left hand tree view by clicking the arror, (just clicking the item itself does not expand the suboptions)
From the suboptions select "Preprocessor Include Paths, Macros etc."
Click the tab "Providers" and check the box next to "CDT GCC Built-in Compiler Settings [ Shared ]".

I had a lot of these errors whicle to trying to get CODAN to run over some code which was destined for a Mac. My Mac SDK libraries were included via symlinks as in this question (but not all of them - stay tuned!) In the end, it turned out that I didn't have all the headers included. For example, I had the following function call:
IORegistryEntryGetParentEntry(service, kIOServicePlane, &parent);
Which was giving the error:
Invalid arguments 'Candidates are: ? IORegistryEntryGetParentEntry(?,?,?)'
Now, the correct signature of the function, defined in IOKit/IOKitLib.h (which I did have) is:
kern_return_t IORegistryEntryGetParentEntry(
io_registry_entry_t entry,
const io_name_t plane,
io_registry_entry_t *parent );
Now, if we take the first argument and trace the type definitions, we get:
typedef io_object_t io_registry_entry_t; (in IOKit/IOTypes.h)
typedef mach_port_t io_object_t; (in IOKit/IOTypes.h)
typedef mach_port_name_t mach_port_t; (in mach/port.h)
typedef natural_t mach_port_name_t; (in mach/port.h)
And then! I didn't have the include which defined __darwin_natural_t. This include was actually in i386, which I didn't have in my symlink directory. Adding it completed the chain:
typedef __darwin_natural_t natural_t; (in i386/vm_types.h)
typedef unsigned int __darwin_natural_t; (in i386/_types.h)
Finally, CODAN knew what type argument 1 of IORegistryEntryGetParentEntry() was supposed to be, and the error changed to:
Invalid arguments 'Candidates are: kern_return_t IORegistryEntryGetParentEntry(io_registry_entry_t ,?,io_registry_entry_t*)'
I repeated this "type-trace" for the other arguments, and found that the error disappeared (I didn't even need to rebuild the index, but YMMV). Of course, you would need to find the headers that you need and may sure they are included - the above is just an example!

I had the same problem with a few functions as well. It turned out that the argument was, after several typedefs, an __int64, which is not defined (not standard). I only had to define it in my project and this solved the problem.
Project->Properties->C/C++ General->Paths and Symbols->Symbols->C++ Source File->add
name: __int64
value: long long
(or instead of "long long" maybe you could use one of the values from this answer)
Edit:
By the way, I saw a bug report about this very issue in the Eclipse bugzilla, so maybe defining __int64 won't be necessary in the future

Related

VS2017 Debugger : has no address, possibly due to compiler optimizations

Seems not relevant to some questions with similar titles.
//some other code
std::string s = Lookup->getName().str();
-> break here //some other code
Note: "Lookup" is clang::DirectoryLookup http://clang.llvm.org/doxygen/classclang_1_1DirectoryLookup.html, "Lookup->getName()" is llvm::StringRef http://llvm.org/doxygen/classllvm_1_1StringRef.html.
When break at the above place, in the "Watch" pane in VS2017, the string variable "s" is initialized successfully and its value can be shown in "Watch" pane.
But when try to show(watch) the expression "Lookup->getName().str()" which is just how "s" is initialized, it says:
Lookup->getName().str() | Function llvm::StringRef::str has no address, possibly due to compiler optimizations.
the source code of StringRef::str() is:
/// str - Get the contents as an std::string.
LLVM_NODISCARD
std::string str() const {
if (!Data) return std::string();
return std::string(Data, Length);
}
And all the libraries is in debug version. Based on the above fact, there seems to be no reason for this to happen.
Such thing happens in other situations during debuging a Clang Libtooling program and it make debugging very hard.
What is the possible reason and how to solve it?
I tried #user15331850 solution and it didn't help, but setting Linker-> Debugging-> Generate Debug Info to "/DEBUG:FULL" seems giving me all variables now.
This may be due to optimization option is enabled.
You can disable the same by following these steps:
Right click on the solution
Click on the "properties"
From the left pane, click on the "Configuration Properties"
Click on "C/C++" from the sub-option
Then click on the "optimization" and select "Disabled(/Od)" from the list
That's it. Hope it works for you!!
I had this issue. I needed to change the settings for: Linker-> Debugging-> Generate Debug Info from "/DEBUG:FASTLINK" to "/DEBUG".

Where can I find the declaration of mscorlib::_AppDomain, mscorlib::_Type etc

I am using this for my base https://code.msdn.microsoft.com/CppHostCLR-e6581ee0/sourcecode?fileId=21953&pathId=1366553273
But in my VS2010 I cant get intellisense or go to declaration. I tried google, but it takes me to the .NET documentation.
For example I cant get arguments for (or find where its declared): spDefaultAppDomain->Load_2(bstrAssemblyName, &spAssembly);
_AppDomainPtr spDefaultAppDomain = NULL;
_AppDomainPtr is basicly mscorlib::_AppDomain..
Sorry, since I don't have much experience in this type of coding I don't know how to properly formulate the question.
I found an answer here.
This is how this example declares it:
#pragma comment(lib, "mscoree.lib")
#import "mscorlib.tlb" raw_interfaces_only\
high_property_prefixes("_get","_put","_putref")\
rename("ReportEvent", "InteropServices_ReportEvent")
using namespace mscorlib;
I have tested this in VS2017, for this compiler be sure to set Conformance mode to No in C/C++/Language setting for it to compile properly.
You can use OLEView.exe and scroll down to Type Libraries in the navigation pane, find the proper type library, right click and click View, there are the declarations.

How to configure Eclipse/CDT/C++ formatter to not break line between a function returned type and the function name [duplicate]

I ran into a problem with the Eclipse formatter. It won't format my code correctly when declaring methods within a class declaration. It puts a new line after the method's return type.
I already exported the style xml file and examined the settings in it, but none of the settings have any apparent connection to this problem, and the settings editor in Eclipse didn't show the same problem happening in it's sample code for method declarations.
Here is an example bit of code for what I want to have happen:
class MyClass
{
public:
MyClass();
void myMethod();
};
However, this is what I get:
class MyClass
{
public:
MyClass();
void
myMethod();
};
Again, in the styles editor, the code doesn't have this problem and looks just how I want it to, but in the actual code, the story is different.
I'm using version 3.8.0. Any help is appreciated.
Edit: I deleted those source files that were formatted incorrectly (after formatting the code several times to no avail) and replaced them with "identical" files with the same methods, same structure, etc. I formatted the code this time and it worked. This is probably a bug, but I'm leaving it up just in case anyone else encounters a similar problem or has a solution to avoiding this problem in the first place.
I hand edited two files under the main eclipse projects directory
.metadata\.plugins\org.eclipse.core.runtime\.settings
The two files:
file 1: org.eclipse.cdt.core.prefs, change this line from "insert" to "do not insert"
org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration=do not insert
file 2: org.eclipse.cdt.ui.prefs,
scan this file for "insert_new_line_before_identifier_in_function_declaration" and make a similar change from insert to do not insert next to it, should be obvious
Note I seen this problem on indigo and juno, the fix described above was in juno.
If you have a custom formatter config, export it first (settings>C/C++ General>Formatter>Edit>Export). Then change the following line to "do not insert". Save the XML.
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration" value="do not insert"/>
Delete the current config and import the one you changed.
There's a specific preference in the formatter options starting from cdt 9.8 included in Eclipse 2019-06.

Include Alien in portable app, C++

Ok, I've searched quite a bit, but seem unable to find an answer or example for how to achieve this.
Basically, I have an app that is designed to be portable (built using VC++ in VS2010, but no MFC or managed components, raw WinAPI). I have Lua 5.2 built into it and allow the user to write scripts inside the application. I have multiple glued functions which are exposed to the Lua scripts which handle various WinAPI calls.
However, what I'd like to be able to do is allow the user to write a script in which looks something like this:
require[[Alien/alien]]
local mb = alien.User32.MessageBoxA
mb:types{ 'long', 'long', 'string', 'string', 'long' }
print(mb(0, "Hello World!", "Test", 64))
I simply cannot seem to find a way to do this. I do not want to require the user to install Lua for Windows and, ideally, there be no core.dll and struct.dll from alien; when I tried to do something with those DLLs in ./alien/, it was crashing in Lua5.1.dll because I had LuaForWindows installed, I uninstalled LFW, and then it just states that Lua5.1.dll is missing. I have Lua 5.2 built into my app, so obviously the core/struct DLLs from the Alien rock are expecting Lua5.1.dll to be in the path.
I made a worthless attempt to try to including the Alien src into the project, but doesn't seem to work that way either.
Any ideas would be greatly appreciated. I'd prefer it all be contained in my app, but I'll settle for a solution which involves including the libraries in my project to build and bundle in the distribution if that's the only alternative.
Thanks!
UPDATE:
Ok, thank you Ben Voigt! I think I'm almost there. I've pulled in core.c and struct.c and made sure all the paths are there for libffi. Everything compiles without issue, until I try to call luaopen_alien_core in core.c (the alien.core src file), claiming the identifier is undeclared. I've tried to declare the function signature in my separate source file that's trying to make the call, the compile gets further, but fails complaining of an unresolved external.
Clearly this is likely now a general C++ issue (as I'm only a novice in this area). Here's the general idea of what I have:
//core.c (from Alien project)
(...)
int luaopen_alien_core(lua_State *L) {
alien_register_library_meta(L);
alien_register_callback_meta(L);
alien_register_function_meta(L);
alien_register_buffer_meta(L);
lua_getglobal(L, "alien");
if(lua_isnil(L, -1)) {
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setglobal(L, "alien");
}
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setfield(L, -3, "core");
alien_register_main(L);
return 1;
}
//mysource.c (the file attempting to call luaopen_alien_core(L))
void initLua()
{
L = luaL_newstate();
luaL_openlibs(L);
luaopen_alien_core(L);
(...)
}
This fails to start compiling, issuing the error:
error C3861: 'luaopen_alien_core': identifier not found
Which makes sense, so I add the following line to myheader.h:
int luaopen_alien_core(lua_State *L);
This compiles, but fails to link with:
error LNK2001: unresolved external symbol "int __cdecl luaopen_alien_core(struct lua_State *)" (?luaopen_alien_core##YAHPEAUlua_State###Z)
I've tried several things I can think of, with my limited experience, but nothing will satisfy this error. I even tried to move the contents of core.c into mysource.c, but that creates a whole different mess and seemed to be the wrong way to go as it is.
I'm hoping, and imagining, this is something really stupid, but I'm just not sure how to get it to call luaopen_alien_core, which seems to be the final piece I need.
Thanks again!
}
I imagine that the require directive both loads a dynamic library and adds its contents to the active Lua engine.
By linking alien directly into your code, you obviate the need for the dynamic library. But the content enumeration code won't have run, and you can't use require to run it, or else it'll go looking for a DLL file (along with all the DLL dependencies).
So, you should find out what functions that require directive calls after loading the DLL, and call those when creating a Lua engine. Then it will neither be necessary nor allowed for the script to start with require [[Alien/alien]], but Alien objects will be available.

Visual C++ - Throwing unhandled exception from setting forms icon?

I can compile the solution with no errors, but when I'll try to run it, I get a crash window:
An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "<myformname>.resources" was corerctly embedded or linked into assembly "<myprojectname>" at compile time, or that all the satellite assemblies required are loaded and fully signed.
And after I press Break it throws me to the line:
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
If I comment this line out, everything works just fine, but my program doesn't have icon.
Anyone else had this problem? Found a solution? I couldn't find anything clear enough for me to understand, problem is really annoying me, only solution I found was to declare my form class before any other classes, but I don't even have any other classes in my solution?
I also have only one project in this solution, ms support said something about having multiple projects, which I don't have, so it was no use either.
Take a look here :
http://www.mztools.com/articles/2005/MZ2005007.aspx
The exception is thrown because your icon cannot be located. You will probably need to compiles your resources under one .dll and put this under en-US subfolder on your project output. It did the trick for me at least. There are probably other solutions to your problem too.
Do not panic like I did. The root cause of the problem is that the compiled resource file is different from the one that is asked to load at runtime. This happens because the underlying build-script cannot detect the filename or namespace changes made after the form is created.
For example, At first we started a project named x . And our $(RootNamespace) becomes x. And we created a form named y. So our XML resource file y.resx gets compiled into x.y.resource . At this point the icon change works.
Now somehow we changed the project name or the namespace to z. But our $(RootNamespace) remains the x. While at compile-time it wrongly generates old x.y.resource, but at links-time it links z.y.resource. And at this point the icon change does not work.
It can also happen if the form is under some nested namespace which is not known in the project file.
It can be fixed by changing the compilation output of the y.resx file . It can be done by right-clicking the resource and changing the Resource Logical Name to $(RootNamespace).%(Filename).resources .
I will also make sure that ProjectName,AssemblyName and RootNamespace are the same in the .vcxproj file. Somehow if the form is declared under a nested namespace like RootNamespace.gui , then the output file of the resource should be $(RootNamespace).gui.%(Filename).resources .