Board index » cppbuilder » Can't find SYSTEM.OBJ for linking in a .PAS file

Can't find SYSTEM.OBJ for linking in a .PAS file

My project is now compiling my .PAS file, since I included the correct
directories to find SYSTEM.PAS. Now the linker cannot find SYSTEM.OBJ which
does not even exist.

Does anyone have a similar experience or a solution?

Thanks,
Greg

 

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


: "Greg Toews" <gto...@pacificcoast.net> wrote:

Quote
>My project is now compiling my .PAS file, since I included the correct
>directories to find SYSTEM.PAS.

Remove that directory again. You must not compile SYSTEM.PAS.

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


Stefan Hoffmeister (TeamB) <Stefan.Hoffmeis...@Econos.de> wrote in message

Quote
> Remove that directory again. You must not compile SYSTEM.PAS.

When I leave in the directory my file will compile but not link.
When I remove the directory it won't even compile because it says it cannot
find SYSTEM.PAS.

This is really confusing.

Greg

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


: "Greg Toews" <gto...@pacificcoast.net> wrote:

Quote
>When I leave in the directory my file will compile but not link.

Remove the directory and fix your library path (Tools | Environment
Options... Library)

Quote
>This is really confusing.

You somewhere played with the path settings, removed the reference the
System files and you are now paying for it, I am afraid.

Just to make sure - you do have a VCL-enabled application, don't you?

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


Now it works and I have no idea why.

Each time I create the project by selecting New... from the File menu and
then selecting DLL. Then I add my source files and paste in code to the main
.cpp file. Sometimes it wouldn't compile, sometimes it wouldn't link and now
it does both!

What determines VCL-enabled?

Greg

Stefan Hoffmeister (TeamB) <Stefan.Hoffmeis...@Econos.de> wrote in message
news:5V3hN009lp3jHFQKybBaWf384wsz@4ax.com...

Quote
> : "Greg Toews" <gto...@pacificcoast.net> wrote:

> >When I leave in the directory my file will compile but not link.

> Remove the directory and fix your library path (Tools | Environment
> Options... Library)

> >This is really confusing.

> You somewhere played with the path settings, removed the reference the
> System files and you are now paying for it, I am afraid.

> Just to make sure - you do have a VCL-enabled application, don't you?

> --
> Stefan Hoffmeister (TeamB)     http://www.econos.de/
> Please do apply judgement when sending email.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


Now that everything is compiling/linking ok I need (hopefully) one last bit
of help.
I want to call a pascal function (obviously in my .pas file) from my .cpp
file.
To call a c function in another cpp file all I do is create a declaration in
a .h file.
So far this does not work for the pascal function.

The linker says that there is an unresolved external Convert_CMN_to_SRF(char
*) referenced from WinTSS.OBJ

My DLL WinTSS.CPP file looks like this (relevant code only):

USEUNIT("CMN2SRF.pas");
// declare the dll function
extern "C" __declspec(dllexport) int _stdcall dll_cmn2srf(char
file_cmn[512]);
// implement the dll function by calling the pascal function
int _stdcall dll_cmn2srf (char file_cmn[512])
{
  return Convert_CMN_to_SRF(&file_cmn[0]);

Quote
}

My Pascal file (CMN2SRF.PAS) looks like this:

UNIT CMN2SRF;
    {$B+,C+,I+,R-,V+,U-,D+,K-} // old directives - need to check
INTERFACE
    TYPE
      StrArr = PACKED ARRAY [1..512] OF char;
      StrPtr = ^StrArr;
    FUNCTION  Convert_CMN_to_SRF (  CMN_File : StrPtr ) : integer;
IMPLEMENTATION
    FUNCTION  Convert_CMN_to_SRF (  CMN_File : StrPtr ) : integer;
      BEGIN
        <code>
        Convert_CMN_to_SRF := 1;
      END;

    BEGIN
    END.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


: "Greg Toews" <gto...@pacificcoast.net> wrote:

Quote
>What determines VCL-enabled?

The way you create your project. OWL projects are not VCL-projects; you
can choose not to use the VCL in some command-line projects.

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


: "Greg Toews" <gto...@pacificcoast.net> wrote:

Quote
>I want to call a pascal function

Add the Pascal file to your project; C++Builder will automatically
generate a HPP file. #include that HPP file.

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


Thanks... but that just changed the error message to:

Unresolved external '__fastcall Cmn2srf::Convert_CMN_to_SRF(char *,char
*,char *,char *,char *,char *)' referenced from
D:\Projects\WinTSS\WinTSS.obj

I tried adding Cmn2srf.obj to the project but that made no difference. I
recreated the project from scratch again as well.

Is there a particular way I need to define the function in the .PAS file? My
previous message shows what is there currently.

Greg

Stefan Hoffmeister (TeamB) <Stefan.Hoffmeis...@Econos.de> wrote in message
news:1kviN9SSwTxXoaWI6bo6GRpKUbPr@4ax.com...

Quote
> : "Greg Toews" <gto...@pacificcoast.net> wrote:

> >I want to call a pascal function

> Add the Pascal file to your project; C++Builder will automatically
> generate a HPP file. #include that HPP file.

> --
> Stefan Hoffmeister (TeamB)     http://www.econos.de/
> Please do apply judgement when sending email.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


: "Greg Toews" <gto...@pacificcoast.net> wrote:

Quote
>Unresolved external '__fastcall Cmn2srf::Convert_CMN_to_SRF(char *,char
>*,char *,char *,char *,char *)' referenced from
>D:\Projects\WinTSS\WinTSS.obj

Based upon this:

type
  StrArr = PACKED ARRAY [1..512] OF char;
  StrPtr = ^StrArr;

  function Convert_CMN_to_SRF(CMN_File: StrPtr): Integer;

I am quite surprised about the error message you get. What is the exact
header file translation?

Quote
>Is there a particular way I need to define the function in the .PAS file?

No.

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


The Cmn2srf.hpp file looks like this:
The function actually has 6 parameters (all type StrPtr) I just shortened it
for readability.

#pragma delphiheader begin
#pragma option push -w-
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit

//-- user
supplied -----------------------------------------------------------

namespace Cmn2srf
{
//-- type
declarations -------------------------------------------------------
typedef char StrArr[512];

typedef char *StrPtr;

//-- var, const,
procedure ---------------------------------------------------
extern PACKAGE int __fastcall Convert_CMN_to_SRF(StrPtr CMN_File);

Quote
} /* namespace Cmn2srf */

#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Cmn2srf;
#endif
#pragma option pop // -w-

#pragma delphiheader end.
//-- end
unit ----------------------------------------------------------------
#endif // Cmn2srf

Stefan Hoffmeister (TeamB) <Stefan.Hoffmeis...@Econos.de> wrote in message

Quote
> I am quite surprised about the error message you get. What is the exact
> header file translation?

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


: "Greg Toews" <gto...@pacificcoast.net> wrote:

Quote
>The Cmn2srf.hpp file looks like this:
>The function actually has 6 parameters (all type StrPtr)

The reason for the problem is that DCC32 generates different information
for the

    StrArr = PACKED ARRAY [1..512] OF char;
    StrPtr = ^StrArr;

part than the C++ compiler, namely:

Object Pascal: '__fastcall File1::Convert_CMN_to_SRF(char[512] *)'
C++          : '__fastcall File1::Convert_CMN_to_SRF(char *)'

Solution:

Change the Object Pascal code to read

  StrPtr = PChar;

WARNING: PChar's are zero-based, i.e. they are indexed [0..512-1]. You can
get around this conveniently by declaring

  type
    StrArr = packed array[1..512] of Char;
    StrPtr = ^StrArr;

  function Convert_CMN_to_SRF(InterfacedCMN_File: PChar): Integer;
  var
    CMN_File: StrPtr absolute InterfacedCMN_File;
  begin
    ...
  end;

Which solution you emply is up to you; looking at your Pascal code and
realising that it probably ump{*word*249} years old and rather DOS-centric, I
would recommend a complete rewrite based on a proper string type
(AnsiString or String), anyway.

In case you have questions about the Object Pascal code I recommend asking
them in the Delphi .objectpascal group. I would rather not want to see a
flame war on "get your frigging Pascal out of this C++ IDE group" here
;-).

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Can't find SYSTEM.OBJ for linking in a .PAS file


Moments before I read your last message I made the discovery that the
problem was related to parameters, I eliminated StrPtr and used StrArr for
all parameters and the code compiled at last!!!

Thank you for all the help and the suggestions for passing the string
parameters.

You are correct that the code is very old.
The code is 5000 lines and has too many GOTOs so I don't think I'll rewrite
it.
I insist on not taking credit for the GOTOs since the code was written by
someone else.  :)

Thanks again,
Greg

Stefan Hoffmeister (TeamB) <Stefan.Hoffmeis...@Econos.de> wrote in message

Quote
> The reason for the problem is that DCC32 generates different information
> for the

>     StrArr = PACKED ARRAY [1..512] OF char;
>     StrPtr = ^StrArr;

Other Threads