?
Solved

How do I link a 3rd party library/api into my c++ programs using bcc32?

Posted on 2003-03-14
13
Medium Priority
?
212 Views
Last Modified: 2010-04-01
Hi everyone!

I wonder if anyone can help me out.  I have recently started programming with C++, and I am trying to create a portable application using the wxWindows API [http://www.wxwindows.org/], using the free download of the Borland C++ compiler (bcc32) under WindowsXP.  I have managed to follow the instructions in the wxWindows documentation and have installed the library into the default 'C:\wxWindows_2.4.0\' folder.  bcc32 is installed into the default 'C:\Borland\ folder', and my source code is in 'C:\src\'.  I have also compiled the library (producing a .lib file in 'C:\wxWindows_2.4.0\Lib\'), and have successfully compiled and run a sample program supplied with wxWindows.

My problem is that when I try to compile a Hello World program, as described by the wxWindows tutorial, the compiler complains that it cannot find the 'wx/wx.h' header file that I am required to include in my source.  I tried to solve the problem by copying the contents of 'C:\wxWindows_2.4.0\Include\wx\' to 'C:\Borland\Include\wx', but the compiler then complained that it could not find the 'setup.h' header file which I think is required by the 'wx.h' header.  I located 'setup.h' in another folder and copied this to 'C:\Borland\Include\wx' and tried to compile again, but this time the compiler complained that it could not find 'HelloWorldApp.h' - a header file written by me and placed into the same folder as the .cpp source file ('C:\src\').  I should mention that I am running the compiler from the 'C:\src\' folder when trying to compile my program, but I used the supplied makefile from inside the 'C:\wxWindows_2.4.0\Samples\' folder when I successfully built the sample program.

I think my problem is that I do not know how to set up the wxWindow library so that the compiler can find everything that it needs.  Everything I have done up until now has just used the standard-library.  I have triple checked my source code and I am confident that this is not causing any problems.  Also I am trying to do everything from the command line, i.e. without an IDE.  What is confusing me is that the sample apps provided with the library compile just fine, but my own app won't.  Do I need to write a makefile for my app?

If anyone can help point me in the right direction I would be very grateful.  Thanks for your time, and sorry for the long post :-)

Tim Grocott

P.S. I am aiming to write a DNA/protein sequence analysis application that will port between PC and Mac.  If I ever get it working it will save myself and others a lot of time at work!  It will be open source, free for academic/educational use, and probably licensed under the GPL.
0
Comment
Question by:TimGrocott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8141422
Not sure if this is the cause of the problem, but when you include a file in the same directory as your source (as opposed to the include directory) you have to use "file.h" instead of <file.h>.
0
 

Author Comment

by:TimGrocott
ID: 8142031
Hi DarthNemesis!

Thanks for posting.  I wasn't aware there was a difference between <file.h> and "file.h".  I changed the .cpp file to use <> instead of "" and it has certainly made a difference :-)  Now the linker can find the file OK, but it produces a gazillion "Error: Unresolved external . . . " messages referenced from "HelloWorldApp.obj", so the core problem remains.

Thanks again,

Tim Grocott
0
 
LVL 2

Accepted Solution

by:
DarthNemesis earned 200 total points
ID: 8143526
Unresolved externals are caused when you have prototype function headers but you never define the bodies. If your 'HelloWorldApp.h' file has some functions defined that it doesn't implement, that would be the problem. If you implemented them, but they're in a file like 'HelloWorldApp.cpp', do the following steps:

(The ifs and define  are just good programming, to prevent a file from being read twice even if it's included twice)
At the top of HelloWorldApp.h add the lines
#IFNDEF _HELLO_WORLD_APP //(use any name that's going to be unique for your file)
#DEFINE _HELLO_WORLD_APP
And at the bottom add
#INCLUDE "HelloWorldApp.cpp"
#ENDIF

This should clear up your unresolved externals.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TimGrocott
ID: 8143717
The header file, which I'm copying from the tutorial manual, already includes lines equivalent to '#IFNDEF . . .' and '#DEFINE . . .'  Here's a copy of the code in case you can spot something that I'm missing:

// 'HelloWorldApp.h'
   #ifndef _HELLOWORLDAPP_H
   #define _HELLOWORLDAPP_H

   /**
   * The HelloWorldApp class
   * This class shows a window containing a statusbar with the text ‘Hello World’
   */

   class HelloWorldApp : public wxApp
   {
   public:
       virtual bool OnInit();
   };

   DECLARE_APP(HelloWorldApp)

   #endif _HELLOWORLDAPP_H


// 'HelloWorldApp.cpp'
   // For compilers that supports precompilation, includes "wx/wx.h"
   #include <wx/wxprec.h>

   #ifndef WX_PRECOMP
       #include <wx/wx.h>
   #endif

   #ifndef WX_PRECOMP
       #include <wx/wx.h>
   #endif

   #include "HelloWorldApp.h"

   IMPLEMENT_APP(HelloWorldApp)

   bool HelloWorldApp::OnInit()
   {
       wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, "Hello World");
       frame->CreateStatusBar();
       frame->SetStatusText("Hello World");
       frame->Show(TRUE);
       SetTopWindow(frame);
       return true;
   }

I tried adding '#INCLUDE <HelloWorldApp.cpp>' before the last '#endif . . .' in HelloWorldApp.h, and this did stop the unresolved external messages, but these are now replaced by messages about multiple declarations and definitions.

I don't think the code is at fault, mainly becuase I didn't write it :-) - at the end of the day it's only a Hello World program!  I think the problem is the way I've installed the wxWindows library, but I can't find any clues in the supplied documentation.  What I need to know is how to go about installing a third party library so the compiler can link it into my programs.

Thank again,

Tim
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8143772
This is hard to debug, since I don't have the code in front of me or the platform on which to compile it. From the structure of your HelloWorldApp.cpp, though, it seems that the .cpp file should be included directly by your program rather than the .h file. You can remove the #include I told you to add to the .h file.

Now, your main program has to include HelloWorldApp.cpp. Myself being a Windows user and this being a Linux program, I don't know whether this can be done with an #include "HelloWorldApp.cpp" or just #include "HelloWorldApp".

Is there in fact a "main program" that includes HelloWorldApp, or are you compiling HelloWorldApp.cpp directly?
0
 

Author Comment

by:TimGrocott
ID: 8143780
The header file, which I'm copying from the tutorial manual, already includes lines equivalent to '#IFNDEF . . .' and '#DEFINE . . .'  Here's a copy of the code in case you can spot something that I'm missing:

// 'HelloWorldApp.h'
   #ifndef _HELLOWORLDAPP_H
   #define _HELLOWORLDAPP_H

   /**
   * The HelloWorldApp class
   * This class shows a window containing a statusbar with the text ‘Hello World’
   */

   class HelloWorldApp : public wxApp
   {
   public:
       virtual bool OnInit();
   };

   DECLARE_APP(HelloWorldApp)

   #endif _HELLOWORLDAPP_H


// 'HelloWorldApp.cpp'
   // For compilers that supports precompilation, includes "wx/wx.h"
   #include <wx/wxprec.h>

   #ifndef WX_PRECOMP
       #include <wx/wx.h>
   #endif

   #ifndef WX_PRECOMP
       #include <wx/wx.h>
   #endif

   #include "HelloWorldApp.h"

   IMPLEMENT_APP(HelloWorldApp)

   bool HelloWorldApp::OnInit()
   {
       wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, "Hello World");
       frame->CreateStatusBar();
       frame->SetStatusText("Hello World");
       frame->Show(TRUE);
       SetTopWindow(frame);
       return true;
   }

I tried adding '#INCLUDE <HelloWorldApp.cpp>' before the last '#endif . . .' in HelloWorldApp.h, and this did stop the unresolved external messages, but these are now replaced by messages about multiple declarations and definitions.

I don't think the code is at fault, mainly becuase I didn't write it :-) - at the end of the day it's only a Hello World program!  I think the problem is the way I've installed the wxWindows library, but I can't find any clues in the supplied documentation.  What I need to know is how to go about installing a third party library so the compiler can link it into my programs.

Thank again,

Tim
0
 

Author Comment

by:TimGrocott
ID: 8143801
Whoa, sorry - double post.

I should have mentioned that HelloWorldApp.cpp IS the program I'm trying to compile, sorry :-(
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8143852
Nevermind about the windows/linux thing... The forward slashes on the include directives threw me off. I'm going to download wxwindows to see what the problem is.
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8143956
Wow, the documentation is rather overwhelming... This in particular caught my eye, though:

1. Make sure your WXWIN variable is set [e.g add
   set WXWIN=c:\wxwindows_2.4.0
   to your autoexec.bat file]

They also talk about makefiles repeatedly, but you have to be able to compile the program first before you need to worry about that.
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8143964
The full installation instructions can be found in
C:\wxWindows_2.4.0\docs\msw\install.txt under Borland C++ 4.5/5.0/5.5 compilation.
0
 

Author Comment

by:TimGrocott
ID: 8144031
Whoa, sorry - double post.

I should have mentioned that HelloWorldApp.cpp IS the program I'm trying to compile, sorry :-(
0
 

Author Comment

by:TimGrocott
ID: 8144057
Holy cow Darth!

Surely this goes above and beyond the call of duty :-)  You're a true gent!

I have followed all of the instructions in install.txt for the Borland compiler, including setting WXWIN in autoexec.bat.  Like I said, I can compile the sample programs from their own source folders by using their makefiles.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9492038
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: DarthNemesis

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question