1

I'm trying to run an exe containing C++ code, but it keeps giving me an "entry point not found" error.

To start off with, this is a homework assignment based on the solution to an earlier assignment. I compiled that as it was and tried to run the resulting exe, but I got the same issue.

Below is the code that I downloaded.

#include <iostream> //for cout, cin
#include <iomanip> // for setw, fixed, setprecision() manipulators
#include <fstream> //for file input/output
#include <string.h> //for string types usage
#include <cstdlib>
using namespace std;

/*
Structure to store the date
*/
struct Date
{
int month;
int day;
int year;
};

/*
Structure to store Vehicle Options
*/
struct Option
{
string seatMaterial;
int wheelSize;
string stereo;
string winterPackage;
};

/*
Structure to store Vehicles data
*/
struct Vehicle
{
int ID;
string name;
int cylinder;
string trans;

Date manufDate;
Date shipDate;

Option vehicleOptions;

char receiverFlag; // I or D

//for individuals
string ind_first, ind_last, ind_address;

//for dealers
int deal_zip;


};

Vehicle* readVehicleFromFile(int &totalVehicles);
void menu(Vehicle *vehicle, int totalVehicle);
void printHorizontalLine(int width, char border_char );
void printVehicle(Vehicle *vehicle, int totalVehicle, char flags);

/*
* Entry point
*/
int main()
{
Vehicle *allVehicle;
int totalVehicle = 0;
allVehicle = readVehicleFromFile(totalVehicle);

if( allVehicle == NULL )
{
    cout << "allVehicle is NULL" << endl;
    return 0;
}

printVehicle(allVehicle, totalVehicle, ' ');
menu(allVehicle, totalVehicle);

return 0;
}



/*
* Responsible for reading Vehicle records from vehicles.txt into Vehicle     array of structs
*
*
* @param totalVehicle: reference variable which post execution, contains size of Vehicle
* @param return: pointer pointing to the array of structs containing Vehicle data
*/
Vehicle* readVehicleFromFile(int &totalVehicle)
{
char delimiter;
Vehicle *allVehiclePointer;
//input stream for Vehicle data
ifstream allVehicleInFile;

//open Vehicles file
allVehicleInFile.open("vehicles.txt");

//error handling in case file does not exist - start
if( !allVehicleInFile )
{
    cout << "Error opening vehicles.txt" << endl;
    return NULL;
}
//error handling in case file does not exist - end
cout << "Success opening vehicles.txt" << endl;
allVehicleInFile >> totalVehicle;
allVehiclePointer = new Vehicle[totalVehicle];

cout << "totalVehicles: " << totalVehicle << endl;

for(int i = 0; i < totalVehicle; i++)
{
    allVehicleInFile >> allVehiclePointer[i].ID;
    allVehicleInFile >> allVehiclePointer[i].name;
    allVehicleInFile >> allVehiclePointer[i].cylinder;
    allVehicleInFile >> allVehiclePointer[i].trans;
    //get dates
    allVehicleInFile >> allVehiclePointer[i].manufDate.month;
    allVehicleInFile >> delimiter; //delimiter = ':'
    allVehicleInFile >> allVehiclePointer[i].manufDate.day;
    allVehicleInFile >> delimiter;
    allVehicleInFile >> allVehiclePointer[i].manufDate.year;

    allVehicleInFile >> allVehiclePointer[i].shipDate.month;
    allVehicleInFile >> delimiter;
    allVehicleInFile >> allVehiclePointer[i].shipDate.day;
    allVehicleInFile >> delimiter;
    allVehicleInFile >> allVehiclePointer[i].shipDate.year;
}
allVehicleInFile.close();

int dummyID = 0;
allVehicleInFile.open("options.txt");
//read vehicle options
for (int j = 0; j < totalVehicle; j++){
    allVehicleInFile >> dummyID;
   // if (dummyID == 20)
     //   dummyID = 0;
    allVehicleInFile >>      allVehiclePointer[dummyID].vehicleOptions.seatMaterial;
    allVehicleInFile >> allVehiclePointer[dummyID].vehicleOptions.wheelSize;
    allVehicleInFile >> allVehiclePointer[dummyID].vehicleOptions.stereo;
    allVehicleInFile >> allVehiclePointer[dummyID].vehicleOptions.winterPackage;
}

allVehicleInFile.close();
allVehicleInFile.open("owner.txt");
//read owner information
for (int k = 0; k < totalVehicle; k++){
    allVehicleInFile >> dummyID;
    //if (dummyID == 20)
      //dummyID = 0;
    allVehicleInFile >> allVehiclePointer[dummyID].receiverFlag;

    if (allVehiclePointer[dummyID].receiverFlag == 'D') //this is a dealer vehicle
        allVehicleInFile >> allVehiclePointer[dummyID].deal_zip;
    else{ // this is an individual's vehicle
        allVehicleInFile >> allVehiclePointer[dummyID].ind_first;
        allVehicleInFile >> allVehiclePointer[dummyID].ind_last;
        getline(allVehicleInFile, allVehiclePointer[dummyID].ind_address);
    }
}
allVehicleInFile.close();

return allVehiclePointer;
}


/*
 * Responsible for printing menu and handling user selection
 *
 *
 * @param Vehicle: pointer pointing to the array of structs containing Hospital Personnel data
 * @param totalVehicle: size of Vehicle
 */

void menu(Vehicle *vehicle, int totalVehicle)
{
int input;
while( true )
{
    cin >> input;
    switch( input )
    {
        case 0:
            // 0 - print all vehicles
            printVehicle(vehicle, totalVehicle, ' ');
            break;
        case 1:
            // 1 - print only vehicles manufactured for dealers
            printVehicle(vehicle, totalVehicle, 'D');
            break;
        case 2:
            // 2 - print only vehicles manufactured for individuals
            printVehicle(vehicle, totalVehicle, 'I');
            break;
        case 3:
            // 3 - print only vehicles with 4 cylinder engines
            printVehicle(vehicle, totalVehicle, '4');
            break;
        case 4:
            // 4 - print only vehicles with premium stereos
            printVehicle(vehicle, totalVehicle, 'P');
            break;
        case 5:
            // 5 - print only vehicles with leather seats
            printVehicle(vehicle, totalVehicle, 'L');
            break;
        case 6:
            // 6 - exit
            exit(0);
    }

}
}

/*
 * Responsible for printing the Vehicle array of structs
 *
 *
 * @param vehicle: pointer pointing to the array of structs containing Vehicle data
 * @param totalVehicle: size of vehicle
 */
void printVehicle(Vehicle *vehicle, int totalVehicle, char flags){

if(vehicle == NULL || totalVehicle < 1 )
{
    return;
}

cout << endl;
printHorizontalLine(85, '*');
printHorizontalLine(85, '*');
for(int i = 0; i < totalVehicle; i++)
{

    if( flags != ' ' )
    {
        if( (flags == 'I' && vehicle[i].receiverFlag != 'I') || (flags == 'D' && vehicle[i].receiverFlag != 'D') || (flags == 'L' && vehicle[i].vehicleOptions.seatMaterial != "Leather") || (flags == '4' && vehicle[i].cylinder != 4) || (flags ==  'P' && vehicle[i].vehicleOptions.stereo != "Premium"))
        {
            // skip roles which do not match roleFlag
            continue;
        }
    }
    // filter - end

    cout.clear();
    cout.fill(' ');

    cout
    << left
    << setw(3)
    << i
    << left << setw(10)
    << vehicle[i].name
    << left << setw(3)
    << vehicle[i].cylinder

    << left << setw(10)
    << vehicle[i].trans
    << left
    << vehicle[i].manufDate.month << ':' << vehicle[i].manufDate.day << ':' << vehicle[i].manufDate.year
    << left << "\t"
    << vehicle[i].shipDate.month << ':' << vehicle[i].shipDate.day << ':' << vehicle[i].shipDate.year
    << "\t" ;

    //print options
    cout << left << setw(10)
    << vehicle[i].vehicleOptions.seatMaterial
    << left << setw(5)
    << vehicle[i].vehicleOptions.wheelSize
    << left << setw(10)
    << vehicle[i].vehicleOptions.stereo
    << left << setw(5) << vehicle[i].vehicleOptions.winterPackage;

    cout << left << setw(3) << vehicle[i].receiverFlag;

    if (vehicle[i].receiverFlag == 'D')
        cout << left << setw(7) << vehicle[i].deal_zip;
    else
        cout << left << setw(3)
        << vehicle[i].ind_first << " " << vehicle[i].ind_last
        << "   "
        << vehicle[i].ind_address;

    cout << endl;
}
printHorizontalLine(85, '*');
printHorizontalLine(85, '*');
cout << endl;
cout << "0 - Print all vehicles" <<endl;
cout << "1 - Print only vehicles manufactured for dealers" << endl;
cout << "2 - Print only vehicles manufactured for individuals" << endl;
cout << "3 - Print only vehicles with 4 cylinder engines" << endl;
cout << "4 - Print only vehicles with premium stereos" << endl;
cout << "5 - Print only vehicles with leather seats" << endl;
cout << "6 - Exit: ";
}


/*
 * Responsible for printing a horizontal line which consists of border_char     characters
 * 
 *
 * @param width: count of border_char
 * @param border_char: width made out of characters
 */
void printHorizontalLine( int width, char border_char )
{
cout.fill( border_char );
cout << setw( width ) << border_char << "\n";
cout.fill(' ');
}

In attempting to find the root of the issue, I isolated code and experimented with it. I found that when I uncommented these two bits of code, it broke.

(flags == 'L' && vehicle[i].vehicleOptions.seatMaterial != "Leather")
(flags ==  'P' && vehicle[i].vehicleOptions.stereo != "Premium")

Here is the full text of the error: "The procedure entry point _ZNKSt7_cxx1112basic_stringlcSt11char_traitslcESalcEE7compareEPKc could not be located in the dynamic link library C:\Users\Zach\Documents\College - Spring 2017\CS 250\Assignment 1\Solution\Vehicles\bin\Debug\Vehicles.exe"

Paradox
  • 19
  • 1
  • 6
  • Can you give the full text of the error there should be more lines than just _"entry point not found"_. See also http://stackoverflow.com/questions/17136315/entry-point-not-found – Richard Critten Feb 25 '17 at 02:18
  • And your code won't compile with that `#include `. `string.h` is for C-string functions which should be in fact `cstring`. You need `#include `. Also you don't use `cstdlib` at all. After fixing that, code compiles and runs just fine on MSVC – mpiatek Feb 25 '17 at 02:22
  • @RichardCritten I added it in. I tried to embed an image earlier, but apparently one needs more reputation for that. – Paradox Feb 25 '17 at 02:27
  • @Paradox what dev environment do you use? Is it MinGW? – mpiatek Feb 25 '17 at 02:40
  • @mpiatek Yes, I have been using that. I've also been using CodeBlocks, but I set the compiler there to g++. – Paradox Feb 25 '17 at 02:41

3 Answers3

3

Same trouble, and PATH was already sets. I just copied libstdc++-6.dll to folder with my .exe and it's works

Dirk Pitt
  • 31
  • 2
1

Locate the directory containing libstdc++-6.dll and add it to your PATH variable.

  1. Open command prompt
  2. Run set PATH=%PATH%;YOUR_PATH_HERE

You can also link statically to the libstdc++. For Code::Blocks you can check this question

or build it using command line:

g++ -c -o main.o main.cpp 
g++ -o main.exe main.o -static-libstdc++
Community
  • 1
  • 1
mpiatek
  • 1,313
  • 15
  • 16
  • I did that and the compiler got mad at me because it said that the exit function at the bottom of the menu function was not declared in that scope. And this is including your suggestion to remove the include on cstdlib. – Paradox Feb 25 '17 at 03:00
  • Remove it or add `#include ` back again. I didn't spot you use it when I wrote my previous comment. Rebuild everything and let me know if it works now. – mpiatek Feb 25 '17 at 03:03
  • I added it back in and the original error persists. Considering how the libstdc++-6.dll is in the bin and I already have the bin in my PATH variables, I don't think that's the problem. – Paradox Feb 25 '17 at 03:05
  • and you have your `MinGW\bin` added to the `PATH`? Follow the instructions from [here](http://www.mingw.org/wiki/Getting_Started) - Section "Environment Settings" – mpiatek Feb 25 '17 at 03:07
  • Yes, I do have that path in there. – Paradox Feb 25 '17 at 03:19
  • @Paradox okay so try to add `-static-libstdc++` to your linking options – mpiatek Feb 25 '17 at 03:32
  • Linking options? Is that something I'd type in the command prompt? – Paradox Feb 25 '17 at 03:41
  • For Code::Blocks look [here](http://stackoverflow.com/questions/23049844/adding-linker-options-to-codeblocks). Otherwise run something like `g++ -c -o main.o main.cpp` then `g++ -o main.exe main.o -static-libstdc++` – mpiatek Feb 25 '17 at 03:55
1

If add to path doesn't work but put libstdc++-6.dll into the program folder does, then you could have a conflict with the paths, try to search in your environment variables the paths with mingw-w64 or similar in it and just leave one.

For example, in my case i have Anaconda and mingw-w64 installed in my pc, and in the environment variables Anaconda had a binaries folder for mingw-w64.

something like: C:\Users\user\anaconda3\Library\mingw-w64\bin

I eliminated it and just leave mingw-w64 binaries path and all my OpenCV programs runs without problems. I hope this help someone, regards!.

K1ltr0
  • 49
  • 6