Procedure Entry Point not found?

Pages: 12
Greetings,

I tried to compile and run a new small program via windows cmd (I usually use an IDE so I am not experienced at using a terminal).
I have 2 source files, my main.cpp and a function.cpp as well as the header of the latter, function.h.

In cmd I type:
g++ -c main.cpp
g++ -c function.cpp

g++ -o main main.o function.o

This creates an exe file but if I try to run it I get the error message that "the procedure entry point [string of cryptic symbols] could not be found in the dynamic link library".

Any idea where the problem is?

My main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 #include "arithmetic_med_from_file.h"
#include <iostream>
#include <string>
using namespace std;

int main(){

string filename;
size_t N;
double result;
cout<<"Type in the name of the file!"<<endl;
cin>>filename;
cout<<"Type in the index N of the row in the file from which you want to start calculating the arithmetic medians (N must not be smaller than number of rows in file)!"<<endl;
cin>>N;

result=arithmetic_med_from_file(N, filename);
cout<< "arithmetic median of the y-values of the last N rows of file '" + filename + "' is :" <<endl;
cout<< result;



return 0;
}


My function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <fstream>
#include <vector>
#include <iostream>
#include <string>
#include "arithmetic_med_from_file.h"

using namespace std;

struct pair_x_y{
double x;
double y;
};

double arithmetic_med_from_file(size_t N, string filename){


vector <pair_x_y> values;

double x,y;
double sum {0};



ifstream data;
data.open(filename);
if(data.fail()){
    cerr<< "Error opening file"<<endl;
    exit(1);
}
while(data >> x >> y){
    values.push_back({x,y});
}
data.close();



for(size_t i=N-1; i<values.size(); ++i){
    sum+=values[i].y;
}
return sum/(values.size()-N+1);

}


The header:
1
2
3
4
5
6
7
8
9
#ifndef ARITHMETIC_MED_FROM_FILE_H_INCLUDED
#define ARITHMETIC_MED_FROM_FILE_H_INCLUDED

#include <string>

double arithmetic_med_from_file(size_t N, std::string filename);

#endif // ARITHMETIC_MED_FROM_FILE_H_INCLUDED

Post the exact "string of cryptic symbols". Also, after "could not be found in the dynamic link library" there should be the name of a DLL. What is it?
"The procedure entry point _ZNKSt7__cxx1112basic_stringlcSt11char_traitslcESalcEE4sizeEv could not be located in the dynamic link library [ABSOLUTE PATH OF calculate_median.exe]"

This is all =(
Last edited on
Your code compiles smoothly in Windows and g++ 7.1.0 by the following instruction:

g++ -std=gnu++17 -Wall -Wextra -pedantic-errors arithmetic_med_from_file.cpp main.cpp -o main.exe
Ok, can you explain the commands or what the problem was with my way?

Also, if I simply type in your commands, I don't get an .exe file.
Also, if I simply type in your commands, I don't get an .exe file.


What do you get? Error messages? Another file? A cup of tea?
starting only with my .cpp and the .h file, I type in what @Enoizat suggested and get:

main.cpp: In function 'int main()':
main.cpp:21:18: warning: unused variable 'V_0' [-Wunused-variable]
const double V_0 {N*PI*(4./3)*R*R*R}; //total volume of N spheres
^~~
C:\Users\name\AppData\Local\Temp\ccqavxrj.o:main.cpp:(.text+0x3dc): undefined reference to `MCMC_hard_spheres_constant_p(int, double, double, std::vector<particle, std::allocator<particle> >, double, double, double, double)'
collect2.exe: error: ld returned 1 exit status


A cup of tea would be better...
Last edited on
There is nothing even remotely similar to hard spheres in the main() that you have posted.
There definitely is no line 21: const double V_0 {N*PI*(4./3)*R*R*R}; in your main.cpp.

Have you edited your code, or are you compiling entirely different files?


Did you write:
g++ -std=gnu++17 -Wall -Wextra -pedantic-errors function.cpp main.cpp -o main.exe

Sorry guys, I typed in "function.cpp" and "main.cpp" even though they are only the names I gave them here in this thread above my portrayed code. Ironically, in the same folder I have a "true" main file that was accessed instead.

However, using the real names and typing
g++ -std=gnu++17 -Wall -Wextra -pedantic-errors arithmetic_med_from_file.cpp calculate_median.cpp -o calculate_median.exe
...gives a similar error message as the one from the beginning. It creates an exe, but when I try to run it:
"The procedure entry point _ZNKSt9basic_ioslcSt11char_traitslcEEcvbEv could not be located in the dynamic link library [absolute path to .exe]"
Last edited on
What are are the names of your files? Please, be precise.
arithmetic_med_from_file.cpp
arithmetic_med_from_file.h
calculate_median.cpp

simply the function names.
I’ve created a new folder and copied&pasted your code into the files
- arithmetic_med_from_file.cpp
- arithmetic_med_from_file.h
- calculate_median.cpp

Then, I opened a cmd window and typed:
g++ -std=gnu++17 -Wall -Wextra -pedantic-errors arithmetic_med_from_file.cpp calculate_median.cpp -o calculate_median.exe

Again, it compiled 0 errors 0 warnings.

Shall we try to isolate the problem? Could you please try creating a new folder and putting inside these files:
a.h:
1
2
3
4
5
6
#ifndef A_H
#define A_H

int myfunc();

#endif // A_H 


a.cpp
1
2
3
4
5
6
#include "a.h"

int myfunc()
{
    return 13;
}


main.cpp:
1
2
3
4
5
6
7
#include "a.h"
#include <iostream>

int main()
{
    std::cout << myfunc() << '\n';
}


And then compile them this way:
g++ a.cpp main.cpp -o main.exe

If it compiles, you can later try copying and pasting your code inside them and see if it gives you any errors.

Good luck!
Last edited on
Enoizat wrote:
I’ve created a new folder and copied&pasted your code into the files
- arithmetic_med_from_file.cpp
- arithmetic_med_from_file.h
- calculate_median.cpp

Then, I opened a cmd window and typed:
g++ -std=gnu++17 -Wall -Wextra -pedantic-errors arithmetic_med_from_file.cpp calculate_median.cpp -o calculate_median.exe

Again, it compiled 0 errors 0 warnings.


But does the .exe run? I don't get errors through compiling either, the error comes if I try to run the function. I tried it with a new folder as well, same problem.
I am going to try your suggestion now.

edit: I did the stuff with a.cpp and main.cpp. It worked and I don't get an error, neither in compilation nor in execution.
Last edited on
Ok, so now I copied my code into your "dummy" files (I only had to change the #include command for the header since it is called a.h now):

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "a.h"
#include <iostream>
#include <string>
using namespace std;

int main(){

string filename;
size_t N;
double result;
cout<<"Type in the name of the file!"<<endl;
cin>>filename;
cout<<"Type in the index N of the row in the file from which you want to start calculating the arithmetic medians (N must not be smaller than number of rows in file)!"<<endl;
cin>>N;

result=arithmetic_med_from_file(N, filename);
cout<< "arithmetic median of the y-values of the last N rows of file '" + filename + "' is :" <<endl;
cout<< result;



return 0;
}


a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <fstream>
#include <vector>
#include <iostream>
#include <string>
#include "a.h"

using namespace std;

struct pair_x_y{
double x;
double y;
};

double arithmetic_med_from_file(size_t N, string filename){


vector <pair_x_y> values;

double x,y;
double sum {0};



ifstream data;
data.open(filename);
if(data.fail()){
    cerr<< "Error opening file"<<endl;
    exit(1);
}
while(data >> x >> y){
    values.push_back({x,y});
}
data.close();



for(size_t i=N-1; i<values.size(); ++i){
    sum+=values[i].y;
}
return sum/(values.size()-N+1);

}


a.h
1
2
3
4
5
6
7
8
#ifndef ARITHMETIC_MED_FROM_FILE_H_INCLUDED
#define ARITHMETIC_MED_FROM_FILE_H_INCLUDED

#include <string>

double arithmetic_med_from_file(size_t N, std::string filename);

#endif // ARITHMETIC_MED_FROM_FILE_H_INCLUDED 


Compiling using g++ a.cpp main.cpp -o main.exe works fine, but the .exe file still gives that strange error. That should imply that there is a problem in the code somehow, right?
I could execute your code from the very beginning. I'd write it in another way, but it works (I didn't do the math to check the result, anyway).

Have you read the latest keskiverto's post? I think it could be the solution.

Ok strange.

I have seen it, but I am a bit afraid of messing with my PATH as I have no idea of this stuff =(
PATH just tells the system where to look for executables and DLLs. There's little danger in adding paths at the back.
Ok, but I don't really understand what I am supposed to do.

The whole error looks a bit weird, but I guess your issue is caused by multiple conflicting DLLs in your PATH. You should be able to test this hypothesis by going into c:\mingw\bin, clearing PATH completely (set PATH= in the Windows shell; export PATH= in Bash) and trying to execute as --help again. If that helped, you need to identify what program in your PATH is causing this and either remove it from PATH completely, or remember to set a custom, short, non-conflicting PATH everytime you want to use your mingw installation.


So I should delete my whole PATH? And what does "export in Bash" mean?
Last edited on
Pages: 12