Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Unresolved extrnal



Permlink Replies: 4 - Last Post: Jan 23, 2018 12:13 PM Last Post By: Garrett B Threads: [ Previous | Next ]
Garrett B

Posts: 77
Registered: 10/2/16
Unresolved extrnal
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 22, 2018 4:26 PM
Hi

I am using Embarcadero C++ Builder.
I am trying to use a 3rd party APIs in my application.

My project compiles, but the linker fails, due to unresolved external references.

The instructions for using their APIs within an Embarcadero C project are as follows:
- Include canlib.h.
- Link with the import library canlib32.lib.

I have included the path to their header files in
- Project | Options | Directories and Conditionals | Include path
and the path to their libraries in
- Project | Options | Directories and Conditionals | Library path
I also have included both paths in:
- Project | Options | C++ Compiler | Directories and Conditionals | Include file search path

As a last attempt to resolve the issue, I also copied the dll into the project folder and included it in the project

I am sure there must be a very basic step I am missing here.
Can anyone help?

Thanks

Garrett
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Unresolved extrnal
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 22, 2018 5:57 PM   in response to: Garrett B in response to: Garrett B
Garrett B wrote:

I am using Embarcadero C++ Builder.

Which version? And which compiler are you using - classic or clang?

The instructions for using their APIs within an Embarcadero C project
are as follows:

- Include canlib.h.
- Link with the import library canlib32.lib.

And did you do that?

I have included the path to their header files in
- Project | Options | Directories and Conditionals | Include path

and the path to their libraries in
- Project | Options | Directories and Conditionals | Library path

Did you add the canlib32.lib file to your project?

It is not enough to simply point the project to the folder that
contains the file. You need to actually reference the file so the
linker will use it. So either add the file to your project, or put a
suitable #pragma statement in your C++ code itself.

--
Remy Lebeau (TeamB)
Garrett B

Posts: 77
Registered: 10/2/16
Re: Unresolved extrnal
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 11:51 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Garrett B wrote:

I am using Embarcadero C++ Builder.

Which version? And which compiler are you using - classic or clang?

Version = Embarcadero C++ Builder XE Version 15 (2010)
Compiler = Classic


The instructions for using their APIs within an Embarcadero C project
are as follows:

- Include canlib.h.
- Link with the import library canlib32.lib.

And did you do that?

Yes I did


I have included the path to their header files in
- Project | Options | Directories and Conditionals | Include path

and the path to their libraries in
- Project | Options | Directories and Conditionals | Library path

Did you add the canlib32.lib file to your project?

No I had not.
I had added canlib32.dll file instead


It is not enough to simply point the project to the folder that
contains the file. You need to actually reference the file so the
linker will use it. So either add the file to your project, or put a
suitable #pragma statement in your C++ code itself.

In the end, I removed the .dll file, and then either of the following worked for me:

Adding the .lib file to the project
or
Adding the following line to my code:
#pragma comment(lib, "canlib32.lib")

I am not sure why I thought that it was the .dll file, not the .lib, file I needed to add to my project.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Unresolved extrnal
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 12:05 PM   in response to: Garrett B in response to: Garrett B
Garrett B wrote:

- Link with the import library canlib32.lib.

And did you do that?

Yes I did

Well, no, you didn't, because...

Did you add the canlib32.lib file to your project?

No I had not.

I had added canlib32.dll file instead

Do not add the DLL itself to the project, add its import LIB instead.
The LIB defines the functions that the DLL exports. That info is what
the linker uses to resolve the external references generated by the
compiler.

In the end, I removed the .dll file

Just from the project. Be sure to deploy the DLL with your compiled
EXE, or else the EXE will not load at runtime.

and then either of the following worked for me:

Adding the .lib file to the project

or

Adding the following line to my code:

#pragma comment(lib, "canlib32.lib")

Yes, either of those will work fine.

--
Remy Lebeau (TeamB)
Garrett B

Posts: 77
Registered: 10/2/16
Re: Unresolved extrnal
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 12:13 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thank you Remy for all the information.

Garrett

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02