![](/img/trans.png)
[英]C++ program compiler run the exe file automatically after compiling with g++ command
[英]Entry Point Not Found Error on running c++ .exe file after compiling with mingw g++
我正在使用最新的MinGW在Windows 10上通過g ++編譯器編譯我的c ++代碼。該代碼編譯沒有錯誤,但是當我運行執行文件時,它給出了錯誤: The procedure entry point _ZNSt6chrono3_V212system_clock3nowEv could not be located in the dynamic link library A:\\Code\\DAA Assignments\\2\\outputunsorted1.exe
令人困惑的部分是,使用cygwin編譯時,相同的代碼完全可以運行,但僅在MinGW中會出現此錯誤。 我還嘗試了多次重新安裝MinGW。 我檢查了MinGW文件夾,它確實具有chrono庫,所以為什么找不到入口點。 另一個奇怪的事情是錯誤的結尾顯示“在動態鏈接庫A:\\ Code \\ DAA Assignments \\ 2 \\ outputunsorted1.exe中”,這是我的執行文件的地址,那么為什么程序將其稱為庫? 我的cpp代碼:
#include<iostream>
#include<fstream>
#include<chrono>
#include"quicksort.cpp"
using namespace std;
int main()
{
ifstream inp_file;
ofstream out_file;
ofstream time_file;
//First file
int *arr1 = new int[100000];
int *arr2 = new int[100000];
//Iterative quick sort
inp_file.open("file1.txt");
for(int i=0;i<100000 ;i++)
{
inp_file>>arr1[i];
inp_file>>arr2[i];
}
inp_file.close();
out_file.open("iterative_quick_sorted_file1.txt");
auto start = chrono::high_resolution_clock::now();
iterQuicksort(arr1,0,99999);
auto elapsed = chrono::high_resolution_clock::now() - start;
double microseconds = (double)chrono::duration_cast<chrono::microseconds>(elapsed).count()/1000;
time_file.open("unsorted_iterative_quick_sort_time1.txt");
time_file<<microseconds;
time_file.close();
for(int i=0;i<100000;i++)
{
out_file<<arr1[i]<<"\r\n";
}
out_file.close();
//Recursive quick sort
out_file.open("recursive_quick_sorted_file1.txt");
start = chrono::high_resolution_clock::now();
recQuicksort(arr2,0,99999);
elapsed = chrono::high_resolution_clock::now() - start;
microseconds = (double)chrono::duration_cast<chrono::microseconds>(elapsed).count()/1000;
time_file.open("unsorted_recursive_sort_time1.txt");
time_file<<microseconds;
time_file.close();
for(int i=0;i<100000;i++)
{
out_file<<arr2[i]<<"\r\n";
}
out_file.close();
return 0;
}
quicksort.cpp:
void swap(int *a,int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
int partition (int *arr, int low, int high)
{
int pivot = arr[high]; // pivot
int i = (low - 1); // Index of smaller element
for (int j = low; j <= high- 1; j++)
{
// If current element is smaller than or
// equal to pivot
if (arr[j] <= pivot)
{
i++; // increment index of smaller element
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i + 1], &arr[high]);
return (i + 1);
}
void iterQuicksort(int *arr,int l, int h)
{
int *stack = new int[h - l + 1];
int top = -1;
stack[++top] = l;
stack[++top] = h;
while (top >= 0) {
h = stack[top--];
l = stack[top--];
int p = partition(arr, l, h);
if (p - 1 > l) {
stack[++top] = l;
stack[++top] = p - 1;
}
if (p + 1 < h) {
stack[++top] = p + 1;
stack[++top] = h;
}
}
}
void recQuicksort(int *arr,int l,int h)
{
if(l<h)
{
int pivot = partition(arr,l,h);
recQuicksort(arr,l,pivot-1);
recQuicksort(arr,pivot+1,h);
}
}
用於編譯的命令:
g++ outputunsorted1.cpp -o outputunsorted1
問題出在libstd ++ 6.dll。 通過在g ++中使用參數-static-libstdc++
解決此問題。 MinGW從Windows而不是MinGW中獲取了libstd ++ 6.dll。
您很可能具有舊的編譯器版本,而該版本本身還不支持C ++ 11。 嘗試使用-std=c++11
編譯。 否則,更新編譯器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.