Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: platform independent C++ code


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Feb 12, 2016 12:14 AM Last Post By: Oliver Weinheimer
Oliver Weinheimer

Posts: 73
Registered: 8/20/04
platform independent C++ code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 6, 2016 4:11 PM
Hello,

I am trying to convert parts of a larger project to platform independent C++ code.
So I added all needed files to a win console application (none framework, multithreaded, console application)
then I removed all Win specific headers, vcl stuff etc. (e.g. replacing file operations like FileExists with boost::filesystem functions)
Now it compiles fine, but it does not link.
If "Link with Delphi runtime" is checked it links fine.
But without this, I get a lot of Unresolved external errors.
e.g.
[ilink64 Error] Error: Unresolved external 'System::Sysutils::FormatFloat(System::UnicodeString, long double)' referenced from E:\RADSTUDIO10\LIB\WIN64\RELEASE\RTLE.A|ustring.o
[ilink64 Error] Error: Unresolved external 'System::Sysutils::FloatToStrF(long double, System::Sysutils::TFloatFormat, int, int)' referenced from E:\RADSTUDIO10\LIB\WIN64\RELEASE\RTLE.A|ustring.o
[ilink64 Error] Error: Unresolved external 'System::Sysconst::_SRangeError' referenced from E:\RADSTUDIO10\LIB\WIN64\RELEASE\RTLE.A|dstring.o
[ilink64 Error] Error: Unresolved external 'System::LoadResString(System::TResStringRec*)' referenced from E:\RADSTUDIO10\LIB\WIN64\RELEASE\RTLE.A|syssupp.o
[ilink64 Error] Error: Unresolved external 'System::Syncobjs::TInterlocked::Exchange(void*&, void*)' referenced from E:\RADSTUDIO10\LIB\WIN64\RELEASE\RTLE.A|syssupp.o
[ilink64 Error] Error: Unresolved external 'System::TObject::InheritsFrom(System::TMetaClass*)' referenced from E:\RADSTUDIO10\LIB\WIN64\RELEASE\RTLE.A|syssupp.o

I do not use any Delphi stuff, there is no AnsiString, no UnicodeString, no FloatToStr, ... used.
Definitely FormatFloat or FloatToStrF is not called in my code.

Every hint is welcome.
So far I understand, it should link without "Link with Delpi runtime" checked.

Oliver
Alex Belo

Posts: 626
Registered: 10/8/06
Re: platform independent C++ code [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 6, 2016 10:08 PM   in response to: Oliver Weinheimer in response to: Oliver Weinheimer
Oliver Weinheimer wrote:

I am trying to convert parts of a larger project to platform
independent C++ code. So I added all needed files to a win console
application (none framework, multithreaded, console application)

What IDE are you using?

If this is really pure C++ code try compiling with 3-d party compiler
(MSVC, for example).

I do not use any Delphi stuff, there is no AnsiString, no
UnicodeString, no FloatToStr, ... used. Definitely FormatFloat or
FloatToStrF is not called in my code.

Every hint is welcome.

If you use native IDE...

1) check project file for unwanted stuff and remove it;
2) see (with tdump) if rtl stuff has these dependences. If it has them you
have to add required static libs to link in Studio...

--
Alex

Edited by: Alex Belo on Feb 7, 2016 12:57 PM
Jan Dijkstra

Posts: 206
Registered: 11/4/99
Re: platform independent C++ code [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2016 2:38 AM   in response to: Alex Belo in response to: Alex Belo
Alex Belo wrote:
Oliver Weinheimer wrote:

I am trying to convert parts of a larger project to platform
independent C++ code. So I added all needed files to a win console
application (none framework, multithreaded, console application)

What IDE are you using?

If this is really pure C++ code try compiling with 3-d party compiler
(MSVC, for example).

I do not use any Delphi stuff, there is no AnsiString, no
UnicodeString, no FloatToStr, ... used. Definitely FormatFloat or
FloatToStrF is not called in my code.

Every hint is welcome.

If you use native IDE...

1) check project file for unwanted stuff and remove it;
2) see (with tdump) if rtl stuff has these dependences. If it has them you
have to add required static libs to link in Studio...

--
Alex

Edited by: Alex Belo on Feb 7, 2016 12:57 PM

Check for #pragma link references in your .cpp source files. The IDE has a habit of automatically inserting them whenever you use components. If you remove those components afterwards again, the #pragma link references remain.

Got stung myself with these too. It will try to resolve all #pragma link references during linking, and issue errors if the references can't be resolved.
Oliver Weinheimer

Posts: 73
Registered: 8/20/04
Re: platform independent C++ code [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 9, 2016 12:46 AM   in response to: Jan Dijkstra in response to: Jan Dijkstra
Thanks a lot for the suggestions. I will now try some and hopefully report shortly where the problem was.

Oliver
Goran Ekstrom

Posts: 5
Registered: 10/10/99
Re: platform independent C++ code [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 9, 2016 12:12 PM   in response to: Oliver Weinheimer in response to: Oliver Weinheimer
Oliver Weinheimer wrote:
Thanks a lot for the suggestions. I will now try some and hopefully report shortly where the problem was.

Oliver
It's easy to "check" each pragma; delete a" #pragma link" directive and then save the file, if the directive is needed it will automatically be restored, if it's not it will remain deleted.
Oliver Weinheimer

Posts: 73
Registered: 8/20/04
Re: platform independent C++ code [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 10, 2016 5:17 AM   in response to: Oliver Weinheimer in response to: Oliver Weinheimer
Using TDump showed me clearly that AnsiString is still used in my exe and searching again I found the location - I do not know why search failed the first time. After removing the usage of AnsiString I was able to link without "Link with Delphi Runtime Library" checked. Thanks for your replies - I never used TDump before - it will maybe a help in the future again.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02