OpenCC icon indicating copy to clipboard operation
OpenCC copied to clipboard

Build (in pip package "opencc") fails due to missing `<cstdint>` includes

Open jsoltan226 opened this issue 4 months ago • 1 comments

Adding #include <cstdint> to src/SerialzedValues.hpp and src/SerializedValues.cpp has fixed the issue.

Here's the error log from pip:

[ 36%] Building CXX object src/CMakeFiles/libopencc.dir/PhraseExtract.cpp.o [ 38%] Building CXX object src/CMakeFiles/libopencc.dir/SerializedValues.cpp.o In file included from /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:23: /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.hpp:47:36: error: ‘uint16_t’ was not declared in this scope 47 | std::vector<uint16_t>* valueBytes, | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.hpp:23:1: note: ‘uint16_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ 22 | #include "SerializableDict.hpp" +++ |+#include 23 | /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.hpp:47:44: error: template argument 1 is invalid 47 | std::vector<uint16_t>* valueBytes, | ^ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.hpp:47:44: error: template argument 2 is invalid /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.hpp:48:24: error: ‘uint32_t’ has not been declared 48 | uint32_t* valueTotalLength) const; | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.hpp:48:24: note: ‘uint32_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp: In member function ‘virtual void opencc::SerializedValues::SerializeToFile(FILE*) const’: /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:51:15: error: ‘uint16_t’ was not declared in this scope 51 | std::vector<uint16_t> valueBytes; | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:24:1: note: ‘uint16_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ 23 | #include "SerializedValues.hpp" +++ |+#include 24 | /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:51:23: error: template argument 1 is invalid 51 | std::vector<uint16_t> valueBytes; | ^ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:51:23: error: template argument 2 is invalid /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:52:3: error: ‘uint32_t’ was not declared in this scope 52 | uint32_t valueTotalLength = 0; | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:52:3: note: ‘uint32_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:53:44: error: ‘valueTotalLength’ was not declared in this scope 53 | ConstructBuffer(&valueBuf, &valueBytes, &valueTotalLength); | ^~~~~~~~~~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:55:11: error: expected ‘;’ before ‘numItems’ 55 | uint32_t numItems = static_cast<uint32_t>(lexicon->Length()); | ^~~~~~~~~ | ; /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:56:20: error: ‘numItems’ was not declared in this scope 56 | WriteInteger(fp, numItems); | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:65:13: error: expected ‘;’ before ‘numValues’ 65 | uint16_t numValues = static_cast<uint16_t>(entry->NumValues()); | ^~~~~~~~~~ | ; /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:66:22: error: ‘numValues’ was not declared in this scope 66 | WriteInteger(fp, numValues); | ^~~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:68:18: error: expected ‘;’ before ‘i’ 68 | for (uint16_t i = 0; i < numValues; i++) { | ^~ | ; /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:68:26: error: ‘i’ was not declared in this scope 68 | for (uint16_t i = 0; i < numValues; i++) { | ^ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:69:15: error: expected ‘;’ before ‘numValueBytes’ 69 | uint16_t numValueBytes = valueBytes[valueCursor++]; | ^~~~~~~~~~~~~~ | ; /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:70:24: error: ‘numValueBytes’ was not declared in this scope; did you mean ‘valueBytes’? 70 | WriteInteger(fp, numValueBytes); | ^~~~~~~~~~~~~ | valueBytes /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:63:42: warning: unused variable ‘entry’ [-Wunused-variable] 63 | for (const std::unique_ptr<DictEntry>& entry : lexicon) { | ^~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:62:10: warning: unused variable ‘valueCursor’ [-Wunused-variable] 62 | size_t valueCursor = 0; | ^~~~~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp: In static member function ‘static std::shared_ptropencc::SerializedValues opencc::SerializedValues::NewFromFile(FILE)’: /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:80:3: error: ‘uint32_t’ was not declared in this scope 80 | uint32_t numItems = ReadInteger<uint32_t>(fp); | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:80:3: note: ‘uint32_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:83:11: error: expected ‘;’ before ‘valueTotalLength’ 83 | uint32_t valueTotalLength = ReadInteger<uint32_t>(fp); | ^~~~~~~~~~~~~~~~~ | ; /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:85:22: error: ‘valueTotalLength’ was not declared in this scope 85 | valueBuffer.resize(valueTotalLength); | ^~~~~~~~~~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:94:16: error: expected ‘;’ before ‘i’ 94 | for (uint32_t i = 0; i < numItems; i++) { | ^~ | ; /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:94:24: error: ‘i’ was not declared in this scope 94 | for (uint32_t i = 0; i < numItems; i++) { | ^ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:94:28: error: ‘numItems’ was not declared in this scope 94 | for (uint32_t i = 0; i < numItems; i++) { | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:96:5: error: ‘uint16_t’ was not declared in this scope 96 | uint16_t numValues = ReadInteger<uint16_t>(fp); | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:96:5: note: ‘uint16_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:99:18: error: expected ‘;’ before ‘j’ 99 | for (uint16_t j = 0; j < numValues; j++) { | ^~ | ; /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:99:26: error: ‘j’ was not declared in this scope 99 | for (uint16_t j = 0; j < numValues; j++) { | ^ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:99:30: error: ‘numValues’ was not declared in this scope; did you mean ‘values’? 99 | for (uint16_t j = 0; j < numValues; j++) { | ^~~~~~~~~ | values /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:101:15: error: expected ‘;’ before ‘numValueBytes’ 101 | uint16_t numValueBytes = ReadInteger<uint16_t>(fp); | ^~~~~~~~~~~~~~ | ; /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:102:23: error: ‘numValueBytes’ was not declared in this scope 102 | pValueBuffer += numValueBytes; | ^~~~~~~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp: At global scope: /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:113:52: error: ‘uint16_t’ was not declared in this scope 113 | std::vector<uint16_t>* valueBytes, | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:113:52: note: ‘uint16_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:113:60: error: template argument 1 is invalid 113 | std::vector<uint16_t>* valueBytes, | ^ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:113:60: error: template argument 2 is invalid /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:114:40: error: ‘uint32_t’ has not been declared 114 | uint32_t* valueTotalLength) const { | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:114:40: note: ‘uint32_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp: In member function ‘void opencc::SerializedValues::ConstructBuffer(std::string*, int*, int*) const’: /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:120:40: error: ‘uint32_t’ does not name a type 120 | valueTotalLength += static_cast<uint32_t>(value.length()) + 1; | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:120:40: note: ‘uint32_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:129:19: error: request for member ‘push_back’ in ‘ valueBytes’, which is of non-class type ‘int’ 129 | valueBytes->push_back(static_cast<uint16_t>(value.length() + 1)); | ^~~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:129:41: error: ‘uint16_t’ does not name a type 129 | valueBytes->push_back(static_cast<uint16_t>(value.length() + 1)); | ^~~~~~~~ /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/src/SerializedValues.cpp:129:41: note: ‘uint16_t’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ make[2]: *** [src/CMakeFiles/libopencc.dir/build.make:247: src/CMakeFiles/libopencc.dir/SerializedValues.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:1242: src/CMakeFiles/libopencc.dir/all] Error 2 make: *** [Makefile:166: all] Error 2 building libopencc into /tmp/pip-install-mnbca_ea/opencc_8490b9e6c2f94693bf13978fd6d38672/build/python Traceback (most recent call last): File "/home/user/.local/share/pyenv/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in main() ~~~~^^ File "/home/user/.local/share/pyenv/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) ~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/.local/share/pyenv/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel return _build_backend().build_wheel( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ wheel_directory, config_settings, metadata_directory

.... (PIP backtrace)

jsoltan226 avatar Aug 28 '25 19:08 jsoltan226

The include is already there, but the last release is from 2024.

@BYVoid could a new release be tagged?

C0rn3j avatar Sep 25 '25 09:09 C0rn3j

@lotem another try? It is currently impossible to build opencc for me.

C0rn3j avatar Dec 15 '25 11:12 C0rn3j