프로그래밍/C

tommath library 사용하여 g++, gcc, cl, clang-cl, clang++ 등으로 컴파일 할 때, 에러메시지 해결하기

Scripter 2026. 5. 3. 14:12

 

 

[1] 테스트용 소스 파일 test_main.cpp 의 내용:

 

#include <tommath.h>
#include <stdio.h>

int main() {
    mp_int num;
    mp_init(&num);
    mp_set_int(&num, 12345);
    printf("Number: %d\n", mp_get_int(&num));
    mp_clear(&num);
    return 0;
}

 

[2] 컴파일하기:

$ g++ test_main.cpp -o test_main -ltommath 
test_main .cpp: In function 'int main()':
test_main .cpp:7:15: warning: 'mp_err mp_set_int(mp_int*, long unsigned int)' is deprecated: replaced by mp_set_ul [-Wdeprecated-declarations]
    7 |     mp_set_int(&num, 12345);
      |     ~~~~~~~~~~^~~~~~~~~~~~~
In file included from test_tommath_cpp_001.cpp:1:
include/tommath.h:359:33: note: declared here
  359 | MP_DEPRECATED(mp_set_ul) mp_err mp_set_int(mp_int *a, unsigned long b);
      |                                 ^~~~~~~~~~
test_tommath_cpp_001.cpp:8:38: warning: 'long unsigned int mp_get_int(const mp_int*)' is deprecated: replaced by mp_get_mag_u32/mp_get_u32 [-Wdeprecated-declarations]
    8 |     printf("Number: %d\n", mp_get_int(&num));
      |                            ~~~~~~~~~~^~~~~~
include/tommath.h:356:56: note: declared here
  356 | MP_DEPRECATED(mp_get_mag_u32/mp_get_u32) unsigned long mp_get_int(const mp_int *a) MP_WUR;
      |                                                        ^~~~~~~~~~
test_tommath_cpp_001.cpp:6:12: warning: ignoring return value of 'mp_err mp_init(mp_int*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     mp_init(&num);
      |     ~~~~~~~^~~~~~

 

[3] 수정된 소스 파일 test_main.cpp 의 내용:

#include <stdio.h>
#include <tommath.h>

int main() {
    mp_int num;
    mp_err err_n = mp_init(&num);
    mp_set_i32(&num, 12345);   // <==  mp_set_int(&num, 12345);
    printf("Number: %d\n", mp_get_i32(&num));  // <== printf("Number: %d\n", mp_get_int(&num));
    mp_clear(&num);
    return 0;
}

 

[4] 수정된 소스 파일 test_main.cpp 컴파일하기:

$ g++ test_main.cpp -o test_main -ltommath

 

[5] 생성된 실핼파일 test_main 을 실행한 결과 :

$ ./test_main
Number: 12345