How does Clang handle multiple source files with the same names? - c++

I'm using C++-Builder of RAD 10.2 using the old classic Borland-compiler currently and am using same named source files in some projects. While the file names are identical, the contained classes are placed in different namespaces and those are used as subfolders as well, so the relative path within the project is unique always. Consider the following classes and the dirs they are stored in as example:
view::files_chooser::chosen_files::Dnd
view/files_chooser/chosen_files/Dnd.cpp
view::send_details::recipients::Dnd
view/send_details/recipients/Dnd.cpp
During compilation of the whole project, the following two object files are created:
Win32\Debug\tmp\Dnd.obj
Win32\Debug\tmp\Dnd_0.obj
There's no way to know which object file belongs to which class and in theory it's not a problem if each of them gets compiled always. But if not, it's important to know which object file to replace and the current behaviour is that always the file without index is replaced. Depending on former builds, that might work, if "Dnd_0.obj" contains the other class, but if not, the object file or the other class is missing now and linking fails.
[ilink32 Error] Error: Unresolved external 'view::send_details::recipients::Dnd::~Dnd()' referenced from C:\USERS\[...]\WIN32\DEBUG\TMP\FMSENDDETAILS.OBJ
[ilink32 Error] Error: Unresolved external 'view::send_details::recipients::Dnd::Dnd(view::send_details::recipients::All&, view::send_details::recipients::Events&)' referenced from C:\USERS\[...]\WIN32\DEBUG\TMP\FMSENDDETAILS.OBJ
[ilink32 Error] Error: Unresolved external 'view::send_details::recipients::Dnd::updateDragDetailsSrc(System::TObject *, unsigned int)' referenced from C:\USERS\[...]\WIN32\DEBUG\TMP\FMSENDDETAILS.OBJ
[ilink32 Error] Error: Unresolved external 'view::send_details::recipients::Dnd::disallowRowOn(System::TObject *, unsigned int, bool&) const' referenced from C:\USERS\[...]\WIN32\DEBUG\TMP\FMSENDDETAILS.OBJ
[ilink32 Error] Error: Unresolved external 'view::send_details::recipients::Dnd::onOleDragStop(System::TObject *, int)' referenced from C:\USERS\[...]\WIN32\DEBUG\TMP\FMSENDDETAILS.OBJ
[ilink32 Error] Error: Unresolved external 'view::send_details::recipients::Dnd::updateDragDetailsDest(System::TObject *, unsigned int)' referenced from C:\USERS\[...]\WIN32\DEBUG\TMP\FMSENDDETAILS.OBJ
[ilink32 Error] Error: Unable to perform link
This can easily be reproduced by not compiling the whole project, but only the two individual classes. RAD doesn't seem to use a stable mapping of class file names to object file names, which could easily fix this problem. Some have reported similar problems in Visual Studio, but that seems to provide a way to manually define the resulting file name of the object file. Something which I couldn't find in RAD.
How does Clang handle such cases? Does it store object files within one and the same dir always as well? Does it use some stable naming scheme or is it able to keep the internal relative dir hierarchy of the project?
Thanks!
As requested, the following is an example command line invocation. As it contains the path of the output file to generate (-o.\Win32\Debug\tmp\Dnd.obj), I guess switching to Clang itself doesn't change a thing here, as comments already suggested.
bcc32 command line for "..\..\..\..\src\src\view\files_chooser\chosen_files\Dnd.cpp"
c:\program files (x86)\embarcadero\studio\19.0\bin\bcc32.exe -D_DEBUG;Winapi_MsxmlintfHPP;LOG4CXX_STATIC;XERCES_STATIC_LIBRARY -n.\Win32\Debug\tmp
-I[...] -y -Q -k -r- -c -tM -tW -C8
-o.\Win32\Debug\tmp\Dnd.obj -w-par -Od -v -vi- -H=.\Win32\Debug\tmp\raw.pch -H ..\..\..\..\src\src\view\files_chooser\chosen_files\Dnd.cpp
Success
Elapsed time: 00:00:00.4

Related

Unresolved external symbol symbol __imp_get_function_ptr when compiling a C++ MEX MATLAB API

I am trying to run one of the example codes from the CPP Mex Repository of Matlab R2021a in the VS2017 IDE. Specifically, I am running the phonebook.cpp one. I previously ran with no problems when compiling other solutions in VS2017 with the C Mex API following this guide. However, I get the following message when compiling phonebook.cpp:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __imp_get_function_ptr referenced in function "int (__cdecl*__cdecl matlab::data::detail::resolveFunction<int (__cdecl*)(int,int,bool *)>(enum matlab::data::detail::FunctionType))(int,int,bool *)" (??$resolveFunction#P6AHHHPEA_N#Z#detail#data#matlab##YAP6AHHHPEA_N#ZW4FunctionType#012##Z) test C:\Users\DuuMushishi\Documents\test.obj 1
I am not sure what library needs to be added or if the error is due to something else
I fixed the issue. Turns out I had to include in additional dependencies "libMatlabDataArray.lib" (in my case, located in C:\Program Files\MATLAB\R2021a\extern\lib\win64\microsoft)

Embarcadero Cbuilder [ilink32 Error] Error: Unresolved external 'System::Sysutils::Exception::{1173}...'

I think that I understand the concept "unresolved external symbol means" - the objects were all compiled and during the linking phase the linker could not find the definition (body) of that particular symbol anywhere. So I guess I either have to use the symbol differently or I have to add to the project some missing system library. I am not sure which is correct and how I can check that (no previous experience with RAD).
I am converting some old code (win95) to win10, I started a new project under the latest RAD Studio 10.3 and I added all the source files (add to project) manually. I saw an advice here that I should make sure that the compilers are not mixed. I can see that all source files are compiled with bcc32c. In the documentation I can see that Exception basically provides only various constructors http://docwiki.embarcadero.com/Libraries/Sydney/en/System.SysUtils.Exception .
During the linking phase I get the error above - [ilink32 Error] Error: Unresolved external 'System::Sysutils::Exception::{1173}...'
All the calls were originally Exception("constant") or Exception("constant" + AnsiStringVariable). As most of the problems were caused by old calling schemes I tried to change it to Exception(L"constant") and Exception(L"constant"+UnicodeString), but this is clearly not the problem.
Thanks for any advice.
So clearly this code:
if(x!=S0getb()) Exception("Bad final checksum!");
generates the error in question. The problem is the missing throw. Probably it somehow compiled in the previous versions and nobody noticed. I guess there is a difference between en error code for a missing function symbol and a missing class symbol. But I did not recognized that this is a function call while it should be a new class instance.
The correct code:
if(x!=S0getb()) throw Exception("Bad final checksum!");
fixes the issue.

Linker Errors LNK2019 and LNK1120 in single file code

C++ code of my compiler
There is only one .cpp file in my Win32 console project. I am facing these LNK compile-time errors in my code. I am working on Visual Studio 12. I have tried a lot of things but nothing seems to have solved my issue.
I am writing code for a compiler that was originally built in Java and now the task at hand is to convert it in C++. I am looking forward to some useful solutions.
Can anyone help me with this task?
From the documentation:
unresolved external symbol 'symbol' referenced in function 'function'
The compiled code for function makes a reference or call to symbol,
but that symbol isn't defined in any of the libraries or object files
specified to the linker.
This error message is followed by fatal error
LNK1120. You must fix all LNK2001 and LNK2019 errors to fix error
LNK1120.
You are referencing something not in the file that you are not linking to.
The specific error in the screenshot says that the string terminalEP(void) function being called from the terminalP function does not exist - and it is true because your terminalEP function is definaed as string terminalEP(string str) but the line that calls it from the terminalP function is s=terminalEP();
You need to pass a parameter to the terminalEP function or you need to make the parameter for the terminalEP function have a default value.

How to include C-runtime functions in Delphi component

I am using C++Builder XE2. In my project I use a mix of C++ and Delphi components, which so far has worked great.
I use one particular Delphi component - TATViewer, which is an image viewer. The Delphi files are included in a C++Builder .cbproj project and compile and install just fine.
The component can be extended with JPEG 2000 support by using JasPer JPEG 2000 library, which is written in C, but has a fine Delphi wrapper (http://sourceforge.net/projects/pasjas/). The Delphi wrapper is a single Delphi unit that links in the C .obj files.
Everything compiles, but during linking I run into problems: It cannot find the C library functions used by the JasPer library:
[ILINK32 Error] Error: Unresolved external 'strchr' referenced from C:\COMPONENTS\BCBXE2\ATVIEWER\CBUILDER\JP2IMG.OBJ
[ILINK32 Error] Error: Unresolved external 'atol' referenced from C:\COMPONENTS\BCBXE2\ATVIEWER\CBUILDER\JP2IMG.OBJ
[ILINK32 Error] Error: Unresolved external 'wcscpy' referenced from C:\COMPONENTS\BCBXE2\ATVIEWER\CBUILDER\JP2IMG.OBJ
[ILINK32 Error] Error: Unresolved external 'abort' referenced from C:\COMPONENTS\BCBXE2\ATVIEWER\CBUILDER\JP2IMG.OBJ
The Delphi unit uses the crtl library which is a wrapper around most C libraries, and declares the functions not included in crtl itself:
const
msvcrtdll = 'msvcrt.dll';
//referenced functions, not declared in delphi crtl unit
procedure __assert; external msvcrtdll name '_assert';
procedure _atexit; external msvcrtdll name 'atexit';
procedure _abort; external msvcrtdll name 'abort';
procedure _strrchr; external msvcrtdll name 'strrchr';
How do I get this C++Builder project with Delphi units using C functions to link? I'm sure I must be missing something simple.

Linker error: Unresolved external '__Fastcall_Advgrid::TAdvstringGrid::AutosizeCol......referenced from ...name.OBJ

I was compiling a project, and this project has a unit called Gamespaceframe, the header file was as follow:
:
#include "Advdgrid.hpp"
:
and the .cpp was as follow:
:
#Pragma link "Advdgrid"
:
When I recompiled this project, I got this linker error:
Linker error: Unresolved external '__Fastcall_Advgrid::TAdvstringGrid::AutosizeCol(const int, const int) referenced from C:\MHSS\Gamespaceframe.OBJ.
Any help or comment is appreciated,
Thanks in advance,
Regards,
David.
That linker error means gamespaceframe.obj made a method call to:
__Fastcall_Advgrid::TAdvstringGrid::AutosizeCol(const int, const int)
and the linker could not find the above method anywhere. Since it looks like your gamespaceframe.cpp is including "Advdgrid.hpp" and the hpp extension might indicate a template class inside, I would check and make sure that TAdvstringGrid is instantiated properly.