Eclipse CDT indexer complains about C build-ins as unresolved symbols - c

I have a GCC C based project in Eclipse CDT (Oxygen). In the Problems window, when I go I open C file in the main editor window, it lists bunch of unresolved symbols errors, many for the C and C library built-ins, like __func__.
If I understand it right this is Eclipse' indexer error, as the code compiles & builds fine.
So this is just more of annoyance issue with my Eclipse setup I want to remove. I cannot figure out what is the issue with it however. I've re-indexed N times, double checked includes, compiler / toolchain paths, still doesn't work.
The error(s) would be like:
Symbol '"__func__' could not be resolved
...
Symbol '__asm__ could not be resolved
__func__ is C standard, __asm__ is GCC/GNU keyword..
I tried something from here : https://www.eclipse.org/forums/index.php/t/636348/
no luck.
Anyone knows how to fix the indexer here? Sometimes it also fails to resolve include paths of standard C headers, even though again, the code builds just fine.

Related

Confused by "undefined reference" linker error, and inability to find culprit object file

I have a large, mixed (C, C++) workspace with a complex make file layout. I'm porting in a new library, and working through compilation issues. I have a GNU linker error (in what I am pretty sure is entirely sourced from C code in this instance) of the form:
path/to/object_file.o: In function `function_name':
(.text+0x0x11e4a0): undefined reference to `missing_function'
Now, it is my expectation that if I execute the "strings" command on object_file.o, I should see reference to both function_name and missing_function. I find neither. If I peruse the output of "strings," I do see other symbols that I recognize, so it is not mangling everything.
Is it possible that the linker error message is inaccurate?
I did find the command which builds object_file.o. It is another linker of a bunch of .a files. I executed "strings" on each of them, and did not find function_name in any of them.
So, I am trying to find the build process steps that lead up to this error, as I am not sure that function_name is relevant in this linking step. Any tips on how to do this are appreciated.

"First defined here" error in Eclipse with C

I'm trying to compile a C program using libxml2 in Eclipse. It seems like my code doesn't have problems, but there are errors when I build my project.
The error output is in this screenshot: https://drive.google.com/file/d/0BwV-0_2diIaaQlZHM2Fwa2R0LWc/edit
Before this error, I had an “Undefined reference to” error, but it was because I forgot to link the library libxml2. Now it's the problem in the screenshot. I don't what to do.
[EDITED]
I solved my problem I just need to put -nostartfiles in the linker flags.
I solved my problem I just need to write -nostartfiles in the Linker Flags box :D
To find "Linker Flags" box go to Your Project > Properties > C/C++Build > Settings > GCC C Linker > Miscellaneous
That's it.
Thanks for help.
I don't think your solution is acceptable, I think it will lead to the same problem when your project is executed in other environment (another eclipse configuration, running it from console, etc)
That error occurs when you have defined the same function more than one time in your project, and I bet it's because you have defined the same function you already had in a library.
For example, if I have lib1.h with a function called hello() and then write the same function in your main.c (having that library linked) that problem will occur.
In fact, in your image, I can see "multiple definition of __data_start"
So I think you just have to change the problematic function name and it will be fixed.
In addition, this problem will be caused if you include the same library more than once in your program, but it can be solved using preprocessor (if you are interested in this, google it, since it would be off-topic and make my answer too long)

how to get rid of "LINK : warning LNK4049: locally defined symbol "_xmlFree" imported"?

I build one DLL on windows with microsoft-visual-c 6.0 including the source code from libxml2. Now I have used some xmlFree() calls in my code and I now get the linker warning LNK4049.
I have not the slightest idea, how to get rid of this warning. I googled, but all info I found was above my comprehension (I use normally gcc under solaris). Is there a simple receipt (add/remove compiler-flag or #define/#undef or similar)?
Thanks,
Peter
I was getting this warning when statically linking against libxml2_a.lib with MSVC 11. I haven't tried the DLL version so I'm not sure if it is affected in the same way.
The solution was to define these symbols in your project or makefile to tell the libxml2 header files to assume static linkage and avoid dll-importing and dll-exporting the xmlFree variable at the same time:
LIBXML_STATIC
The same applies to libxslt/libexslt too:
LIBXSLT_STATIC
LIBEXSLT_STATIC
Hope this helps.
I will add bit more context for others who face similar error like following.
We did libxml upgrade from 2.9.4 to 2.9.14 and we observed following errors which are similar to above .
warning LNK4217: locally defined symbol xmlStrcmp imported in function
"void __cdecl ::updateRunElement(struct _xmlNode *,class xml::XmlDoc &,struct _xmlNode *,struct const &)"
(?updateRunElement#YAXPEAU_xmlNode##AEAVXmlDoc#xml#2##2##Z)
LINK : error LNK1218: warning treated as error; no output file generated
warning LNK4217: locally defined symbol xmlFreeDoc imported in function "public: __cdecl xml::XmlDoc::~XmlDoc(void)" (??1XmlDoc#xml##QEAA#XZ)
LINK : error LNK1218: warning treated as error; no output file generated
All the other answers for this error points to set runtime library to /md (Multithreaded dll) or viceversa.
I also tried to suppress these warning by
#pragma warning( disable : 4217 1218) and also by project setting "Disable Specific Warnings" but both did not work as keep giving warnings/errors.
But as #vladimir. (Thanks for the answer) suggested defining LIBXML_STATIC as preprocessor in the project where you are using libxml library either as static or dynamically linked should fix all these warning errors.

How to compile CHOLMOD library (SuiteSparse) from IDE

For some time I am trying to create a static CHOLMOD lib from SuiteSparse Each other library (f.ex. Umfpack) can be easiy compiled from IDE (I used Code::Blocks on Linux and Visual Studio on Windows). However when trying to compile CHOLMOD I get bunch of syntax errors like:
t_cholmod_triplet.c(21): error C2061: syntax error : identifier 'TEMPLATE'
I investigated that there are some #defines missing (like PATTERN, REAL defines) and therefore those definitions of TEMPLATE are invisible. I searched for them in files and in makefiles but found nothing. However when typing make (on Linux) library compiles just fine. What am I missing?
You can use SuiteSparse METIS for Windows package: https://github.com/jlblancoc/suitesparse-metis-for-windows
Credit: Jose Luis Blanco (Universidad de Almeria); Jerome Esnault (INRIA).
Actually the problem exists because of "templates" created in C. It requires to recompile the same code multiple times with different flags. I have written the VS NMakefile based on the original makegile and it compiled it seamlessly.

Compaq Visual Fortran - Crashes During Linking A .LIB File

When I compile with Compaq Visual Fortran, I get these errors (when it starts the linker process) that should be located in a .lib file I thought I added to the workspace:
X30XFULL.OBJ : error LNK2001: unresolved external symbol _BCON#4
X30XFULL.OBJ : error LNK2001: unresolved external symbol _RCON#16
According to where I've googled about, it looks like Compaq Visual Fortran (Version 6, FYI) can't find the library files...
My main question is, how do I use them? Could there possibly be other missing files? Here is what I've tried:
Right Click->Adding the files in the FileView window
Going under Project->Settings, Clicking the Link tab, and under the input category, adding the library files under object/library modules (bprop.lib rprop.lib) and having the Additional Library Path point to where the files are. I also did this under the Resources tab and where it says "Additional Resource Include Directories," I put the directory of where these files were located.
To cover my bases, I also put these files in where the project workspace file, where the compiled executable file would be generated, and pretty much any place I could think of that CVF might possibly look to in order to find these files.
A little background:
I have this Fortran executable that was last compiled in the 90s. From my research, it's a 16-bit compiled one which won't work on a 64-bit machine.
The original code has, at least from what we can gather, 16 bit compiled libraries. Without the original compiler, we can't figure out how to look at or use them. We also have a (semi)equivalent library file that's actually a .FOR file. For all we know, the BPROP.FOR and BPROP.LIB could be the same file (they were found in the same source code area). If we use the BPROP.FOR file, the program can compile, but we are having issues with results that we've traced down to information that is used/gathered/processed in that file.
However, we do have 32-bit versions of (what we think) are the same .lib files. So, we're trying to use that, which is what is being used to compile the Fortran executable which results in the errors above.
Found the answer, at least for me. I don't know how easy it'll be to extrapolate if anyone else finds these answers, but this is how I solved it.
With the old Fortran libraries, all I had to do was add them to the FileList view that has all of the different fortran files (.FOR, etc). I did not have to add these libraries in the settings like I mentioned, but that will work as well. Other then that, I didn't need to add any extra declarations or anything similar.
What we did find out is that the function in question (BCON and RCON) that calls those .LIB files required an additional argument. The only way I found this out was examining other source code that used those libaries, so if anyone is stuck like I was, that would be a good place to start. Alternatively, if you can read the .lib file in a hex editor, you can kind of make out functions and their arguments.
Of course, if you have the original source code for said arguments, that's even better. :)

Resources