MMKV icon indicating copy to clipboard operation
MMKV copied to clipboard

POSIX平台构建demo程序时报错

Open yhuan416 opened this issue 1 year ago • 3 comments

Note:

An crash issue will be ignored & closed in a week without logs.

The language of MMKV

C/CPP

The version of MMKV

e.g. v1.2.2
Note: For versions older than the latest version, please upgrade before posting any issue.
We don't have much time for old version tech support.

The platform of MMKV

POSIX

The installation of MMKV

Git clone

What's the issue?

An error was reported during construction. Referring to the man page, it seems that the demo.cpp file lacks a reference to the header file

demo.cpp

#include "InterProcessLock.h"
#include "MMKV.h"
#include <chrono>
#include <cstdio>
#include <iostream>
#include <limits>
#include <pthread.h>
#include <semaphore.h>
#include <string>
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <cassert>
#include <time.h>

//////////////////////////////////// add start
#include <sys/time.h>
#include <sys/resource.h>
//////////////////////////////////// add end

using namespace std;
using namespace mmkv;

What's the log of MMKV when that happened?

➜  POSIX git:(master) ✗ cd build
➜  build git:(master) ✗ cmake -DCMAKE_BUILD_TYPE=Release ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yhuan/workspace/github/MMKV/POSIX/build
➜  build git:(master) ✗ make
Scanning dependencies of target core
[  2%] Building CXX object src/Core/CMakeFiles/core.dir/MMKV.cpp.o
[  4%] Building CXX object src/Core/CMakeFiles/core.dir/MMKV_Android.cpp.o
[  6%] Building CXX object src/Core/CMakeFiles/core.dir/MMKV_IO.cpp.o
[  9%] Building CXX object src/Core/CMakeFiles/core.dir/MMKV_OSX.cpp.o
[ 11%] Building CXX object src/Core/CMakeFiles/core.dir/MMKVLog.cpp.o
[ 13%] Building CXX object src/Core/CMakeFiles/core.dir/MMKVLog_Android.cpp.o
[ 15%] Building CXX object src/Core/CMakeFiles/core.dir/CodedInputData.cpp.o
[ 18%] Building CXX object src/Core/CMakeFiles/core.dir/CodedInputData_OSX.cpp.o
[ 20%] Building CXX object src/Core/CMakeFiles/core.dir/CodedInputDataCrypt.cpp.o
[ 22%] Building CXX object src/Core/CMakeFiles/core.dir/CodedInputDataCrypt_OSX.cpp.o
[ 25%] Building CXX object src/Core/CMakeFiles/core.dir/CodedOutputData.cpp.o
[ 27%] Building CXX object src/Core/CMakeFiles/core.dir/KeyValueHolder.cpp.o
[ 29%] Building CXX object src/Core/CMakeFiles/core.dir/PBUtility.cpp.o
[ 31%] Building CXX object src/Core/CMakeFiles/core.dir/MiniPBCoder.cpp.o
[ 34%] Building CXX object src/Core/CMakeFiles/core.dir/MiniPBCoder_OSX.cpp.o
[ 36%] Building CXX object src/Core/CMakeFiles/core.dir/MMBuffer.cpp.o
[ 38%] Building CXX object src/Core/CMakeFiles/core.dir/InterProcessLock.cpp.o
[ 40%] Building CXX object src/Core/CMakeFiles/core.dir/InterProcessLock_Win32.cpp.o
[ 43%] Building CXX object src/Core/CMakeFiles/core.dir/InterProcessLock_Android.cpp.o
[ 45%] Building CXX object src/Core/CMakeFiles/core.dir/MemoryFile.cpp.o
[ 47%] Building CXX object src/Core/CMakeFiles/core.dir/MemoryFile_Android.cpp.o
[ 50%] Building CXX object src/Core/CMakeFiles/core.dir/MemoryFile_Linux.cpp.o
[ 52%] Building CXX object src/Core/CMakeFiles/core.dir/MemoryFile_Win32.cpp.o
[ 54%] Building CXX object src/Core/CMakeFiles/core.dir/MemoryFile_OSX.cpp.o
[ 56%] Building CXX object src/Core/CMakeFiles/core.dir/ThreadLock.cpp.o
[ 59%] Building CXX object src/Core/CMakeFiles/core.dir/ThreadLock_Win32.cpp.o
[ 61%] Building CXX object src/Core/CMakeFiles/core.dir/aes/AESCrypt.cpp.o
[ 63%] Building CXX object src/Core/CMakeFiles/core.dir/aes/openssl/openssl_aes_core.cpp.o
[ 65%] Building CXX object src/Core/CMakeFiles/core.dir/aes/openssl/openssl_cfb128.cpp.o
[ 68%] Building CXX object src/Core/CMakeFiles/core.dir/aes/openssl/openssl_md5_dgst.cpp.o
[ 70%] Building CXX object src/Core/CMakeFiles/core.dir/aes/openssl/openssl_md5_one.cpp.o
[ 72%] Building CXX object src/Core/CMakeFiles/core.dir/crc32/crc32_armv8.cpp.o
[ 75%] Building CXX object src/Core/CMakeFiles/core.dir/crc32/zlib/crc32.cpp.o
[ 77%] Linking CXX static library libcore.a
[ 77%] Built target core
Scanning dependencies of target mmkv
[ 79%] Building CXX object src/CMakeFiles/mmkv.dir/libmmkv.cpp.o
[ 81%] Linking CXX shared library libmmkv.so
[ 81%] Built target mmkv
Scanning dependencies of target UnitTest
[ 84%] Building CXX object demo/CMakeFiles/UnitTest.dir/UnitTest.cpp.o
[ 86%] Linking CXX executable UnitTest
[ 86%] Built target UnitTest
Scanning dependencies of target TestInterProcessLock
[ 88%] Building CXX object demo/CMakeFiles/TestInterProcessLock.dir/TestInterProcessLock.cpp.o
[ 90%] Linking CXX executable TestInterProcessLock
[ 90%] Built target TestInterProcessLock
Scanning dependencies of target process
[ 93%] Building CXX object demo/CMakeFiles/process.dir/process.cpp.o
[ 95%] Linking CXX executable process
[ 95%] Built target process
Scanning dependencies of target demo
[ 97%] Building CXX object demo/CMakeFiles/demo.dir/demo.cpp.o
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp: In function ‘void testGetStringSpeed()’:
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:726:29: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
  726 |     printf("old_method = %lld, new_method = %lld\n", end1 - start1, end2 - start2);
      |                          ~~~^                        ~~~~~~~~~~~~~
      |                             |                             |
      |                             long long int                 uint64_t {aka long unsigned int}
      |                          %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:726:48: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
  726 |     printf("old_method = %lld, new_method = %lld\n", end1 - start1, end2 - start2);
      |                                             ~~~^                    ~~~~~~~~~~~~~
      |                                                |                         |
      |                                                long long int             uint64_t {aka long unsigned int}
      |                                             %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:739:29: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
  739 |     printf("old_method = %lld, new_method = %lld\n", end1 - start1, end2 - start2);
      |                          ~~~^                        ~~~~~~~~~~~~~
      |                             |                             |
      |                             long long int                 uint64_t {aka long unsigned int}
      |                          %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:739:48: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
  739 |     printf("old_method = %lld, new_method = %lld\n", end1 - start1, end2 - start2);
      |                                             ~~~^                    ~~~~~~~~~~~~~
      |                                                |                         |
      |                                                long long int             uint64_t {aka long unsigned int}
      |                                             %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp: In function ‘void testCompareBeforeSet()’:
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:816:58: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
  816 |         printf("testCompareBeforeSet: int64_t value = %lld\n", mmkv->getInt64(key));
      |                                                       ~~~^     ~~~~~~~~~~~~~~~~~~~
      |                                                          |                   |
      |                                                          long long int       int64_t {aka long int}
      |                                                       %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:819:58: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
  819 |         printf("testCompareBeforeSet: int64_t value = %lld\n", mmkv->getInt64(key));
      |                                                       ~~~^     ~~~~~~~~~~~~~~~~~~~
      |                                                          |                   |
      |                                                          long long int       int64_t {aka long int}
      |                                                       %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:824:58: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
  824 |         printf("testCompareBeforeSet: int64_t value = %lld\n", mmkv->getInt64(key));
      |                                                       ~~~^     ~~~~~~~~~~~~~~~~~~~
      |                                                          |                   |
      |                                                          long long int       int64_t {aka long int}
      |                                                       %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:832:59: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
  832 |         printf("testCompareBeforeSet: uint64_t value = %lld\n", mmkv->getUInt64(key));
      |                                                        ~~~^     ~~~~~~~~~~~~~~~~~~~~
      |                                                           |                    |
      |                                                           long long int        uint64_t {aka long unsigned int}
      |                                                        %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:835:59: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
  835 |         printf("testCompareBeforeSet: uint64_t value = %lld\n", mmkv->getUInt64(key));
      |                                                        ~~~^     ~~~~~~~~~~~~~~~~~~~~
      |                                                           |                    |
      |                                                           long long int        uint64_t {aka long unsigned int}
      |                                                        %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:840:59: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
  840 |         printf("testCompareBeforeSet: uint64_t value = %lld\n", mmkv->getUInt64(key));
      |                                                        ~~~^     ~~~~~~~~~~~~~~~~~~~~
      |                                                           |                    |
      |                                                           long long int        uint64_t {aka long unsigned int}
      |                                                        %ld
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp: In function ‘void testFtruncateFail()’:
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:1063:19: error: aggregate ‘testFtruncateFail()::rlimit rlim_new’ has incomplete type and cannot be defined
 1063 |     struct rlimit rlim_new,rlim;
      |                   ^~~~~~~~
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:1063:28: error: aggregate ‘testFtruncateFail()::rlimit rlim’ has incomplete type and cannot be defined
 1063 |     struct rlimit rlim_new,rlim;
      |                            ^~~~
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:1065:19: error: ‘RLIMIT_FSIZE’ was not declared in this scope
 1065 |     if (getrlimit(RLIMIT_FSIZE, &rlim) == 0) {
      |                   ^~~~~~~~~~~~
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:1065:9: error: ‘getrlimit’ was not declared in this scope; did you mean ‘rlimit’?
 1065 |     if (getrlimit(RLIMIT_FSIZE, &rlim) == 0) {
      |         ^~~~~~~~~
      |         rlimit
/home/yhuan/workspace/github/MMKV/POSIX/demo/demo.cpp:1067:19: error: ‘setrlimit’ was not declared in this scope; did you mean ‘rlimit’?
 1067 |         int ret = setrlimit(RLIMIT_FSIZE, &rlim_new);
      |                   ^~~~~~~~~
      |                   rlimit
make[2]: *** [demo/CMakeFiles/demo.dir/build.make:63:demo/CMakeFiles/demo.dir/demo.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:283:demo/CMakeFiles/demo.dir/all] 错误 2
make: *** [Makefile:84:all] 错误 2

yhuan416 avatar Apr 25 '24 10:04 yhuan416

You are right. It's a Linux-only feature and should #include <sys/resource.h> .

lingol avatar Apr 25 '24 13:04 lingol

Hey, a quick survey. Is OK for you to switch to C++20? We are considering migrating MMKV to C++20 (specifically for the concept feature).

lingol avatar May 06 '24 02:05 lingol

I usually use C language in the embedded field. Not very familiar with C++20.

yhuan416 avatar May 06 '24 06:05 yhuan416

It's fixed in v1.3.6.

lingol avatar Jul 05 '24 12:07 lingol