Я столкнулся с ошибкой сегментации (дамп ядра) при сборке разделяемой библиотеки для python. Это Python файл
# coding=utf-8
import sys, platform
import ctypes, ctypes.util
path_libc = "cmake-build-debug/libuntitled.so"
MAIN_DICT = 1
# mylib_path = ctypes.util.find_library(path_libc)
# if not mylib_path:
# print("Unable to find the specified library.")
# sys.exit()
try:
libc = ctypes.CDLL(path_libc)
print(libc.getPrediction("tôi cô đơn", MAIN_DICT))
except OSError:
print("Unable to load the system C library")
sys.exit()
print('Succesfully loaded the system C library from', path_libc)
PNI.h
#ifndef UNTITLED_PIN_H
#define UNTITLED_PIN_H
#include <string>
extern "C"
{
// A function doing nothing ;)
int getPrediction(const std::wstring &preword,
int dictType);
}
#endif //UNTITLED_PIN_H
PNI. cpp
#include "PIN.h"
#include "Tesst.h"
int getPrediction(const std::wstring &preword, int dictType) {
Tesst a(preword);
return 0;
}
Tesst.h
#include <string>
class Tesst {
public:
Tesst();
Tesst(const std::wstring& t);
};
Тест. cpp
Tesst::Tesst(const std::wstring& t) {
wchar_t a = t[0];
}
Tesst::Tesst() {
}
Этот код делает python app cra sh с ошибкой сегментации (дамп ядра). Когда я отлаживаю, я вижу, удаляю ли я это утверждение
wchar_t a = t[0];
Все сделано. Код работает. У меня есть вопрос, почему это утверждение делает cra sh (основной дамп).
Спасибо.