2

I'm currently trying to create a Firebird database using C++. Firebird is installed on my computer. My program looks as follows:

#define IBPP_WINDOWS = true
#define IBPP_GCC = true

#include "ibpp.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <cmath>

using namespace std;
using std::vector;
using std::string;
using std::ifstream;
using std::ofstream;
using std::getline;
using std::cin;
using std::cout;
using std::endl;
using std::istringstream;

int main(int argc, char *argv[])
{   
    std::string UserName = "SYSDBA";
    std::string Password = "**********";
    std::string ServerName = "localhost";
    char* DbName = (char *)"C:/Users/**********/Desktop/**********.fdb";

    IBPP::Database db =   IBPP::DatabaseFactory(ServerName,DbName,UserName,Password);

    db->Create();
    db->Connect();

}

When I try to compile my code, I get the following message:

C:\Users**********\AppData\Local\Temp\cc2Zhdj3.o:**********.cpp:(.text$_ZN4IBPP15DatabaseFactoryERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_S7_S7_[__ZN4IBPP15DatabaseFactoryERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_S7_S7_]+0xaa): undefined reference to `IBPP::DatabaseFactory(std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&)' collect2.exe: error: ld returned 1 exit status

Does anyone have an idea what I did wrong?

Wolf
  • 9,679
  • 7
  • 62
  • 108
frau_tana
  • 71
  • 1
  • 8
  • 2
    [You're very likely not linking the appropriate libs to your application.](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix). – WhozCraig Sep 21 '17 at 06:56

3 Answers3

2

As noted by WhozCraig, you are probably not linking with Firebird shared library. If using GCC try adding link option -libpp, in case you are using MSVC, just simply add IBPP .cpp files into your project or create a static library and link with that.

vasek
  • 2,759
  • 1
  • 26
  • 30
  • I typed g++ -libpp **********.cpp in the command window. Now I get the followingerror message: file not recognized: File format not recognized collect2.exe: error: ld returned 1 exit status – frau_tana Sep 21 '17 at 07:25
  • Try splitting compilation and linking process (e.g. `g++ -c file.cpp -o file.o`, then `g++ file.o -libpp -o final.exe`) – vasek Sep 21 '17 at 07:32
  • How is that supposed to work? When i compile it without the lib file, I always get an error message and no .exe file is created at all... – frau_tana Sep 21 '17 at 07:34
  • 1
    If you get compile time error, consider compiling ibpp from the sources you can download and then link everything together. – vasek Sep 21 '17 at 08:38
  • Sorry, but I've never linked libraries before... it sounds fairly easy to just "link everything together", but I don't have any clue what this means and how it is done. plus, i don't know how to compile something from "sources" in the first place... could you maybe explain what you mean in a little more detail? :) I'm sorry to bother you with such minor issues, but right now I don't have a plan what to do. – frau_tana Sep 21 '17 at 10:50
1

This is wrong:

#define IBPP_WINDOWS = true

It should be :

#define IBPP_WINDOWS
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
1

you probably downloaded and unzippped the folder ibpp-2-5-3-1-src. In there you should find the folder core which includes the file all_in_one.cpp. Simply include this file in your program by pasting #include "C:\remaining_path\ibpp-2-5-3-1-src\core\all_in_one.cpp" where you have to insert the remaining part of the path where the file (all_in_one.cpp) is located. You don't have to include the ibpp header additionally since it is already included through the all_in_one file.

This will do the trick :)

And by the way: Never mind that bunch of prats teasing you here. They seem to be complete slaves just doing exactly what authority tells them to, never having learned to think for themselves. I guess they're merely jealous, so as I said: never mind, you'll go places!

frau_tana
  • 71
  • 1
  • 8
  • "this will do the trick" is too often used on no-solutions. The programming languages C and C++ use a two-stage approach to create executables/loadables from source. 1) compiling 2) linking most IDEs hide this separation from their users so the distinction between compiler errors and linker errors (the kind of error you experienced) are hard to see. – Wolf Oct 14 '20 at 07:53