단비) c++ 하더라도 c 알아야 하는 이유
익명(118.216)
2023-07-20 22:56
추천 5
구글 Skia 컴파일하다보면 각종 에러가 나옴.
구글 Skia 주 개발언어는 C++ 인데 군데군데 C 코드 사용됨.
C++ 문법이 대부분의 C 문법을 포함하기 때문에
사실 뭐 C 코드라고 말하기도 뭐시기한데
자료를 보셈.
[720/1533] compile ../../third_party/externals/icu/source/common/appendable.cpp
FAILED: obj/third_party/externals/icu/source/common/libicu.appendable.o
c++ -MD -MF obj/third_party/externals/icu/source/common/libicu.appendable.o.d -DU_COMMON_IMPLEMENTATION -DU_STATIC_IMPLEMENTATION -DU_ENABLE_DYLOAD=0 -DU_I18N_IMPLEMENTATION -D_XOPEN_SOURCE=0 -DSK_TRIVIAL_ABI=\[\[clang::trivial_abi\]\] -DU_USING_ICU_NAMESPACE=0 -DU_DISABLE_RENAMING -DSK_USING_THIRD_PARTY_ICU -w -Wno-attributes -ffp-contract=off -fstrict-aliasing -fPIC -fvisibility=hidden -g -gdwarf-4 -I/usr/local/include -I/usr/local/include/harfbuzz -I/usr/local/include/freetype2 -O3 -fdata-sections -ffunction-sections -isystem /usr/home/hodong/skia/third_party/externals/icu/source/common -isystem /usr/home/hodong/skia/third_party/externals/icu/source/i18n -isystem /usr/home/hodong/skia/third_party/icu -std=c++17 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -frtti -c ../../third_party/externals/icu/source/common/appendable.cpp -o obj/third_party/externals/icu/source/common/libicu.appendable.o
../../third_party/externals/icu/source/common/appendable.cpp:40:24: error: use of undeclared identifier
'FALSE'
return FALSE;
^
../../third_party/externals/icu/source/common/appendable.cpp:47:24: error: use of undeclared identifier
'FALSE'
return FALSE;
^
../../third_party/externals/icu/source/common/appendable.cpp:51:12: error: use of undeclared identifier
'TRUE'
return TRUE;
^
../../third_party/externals/icu/source/common/appendable.cpp:56:12: error: use of undeclared identifier
'TRUE'
return TRUE;
^
4 errors generated.
[725/1533] compile ../../modules/svg/src/SkSVGText.cpp
컴파일하다보면 이렇게 에러가 나기도 함.
c 에는 예전에 bool 자료형이 없어서,
#define TRUE 1
#define FALSE 0
이런 식으로 사용하기도 함.
#define TRUE !FALSE 이렇게 쓰기도 하고.
위 에러는 간단히.. true, false 로 변환하면 될 것 같기도 함.
다만 주의할 점이, 리턴 타입의 크기임.
값 복사이기 때문에 리턴 타입 신경 안 써도 될 거 같기도 하고.
그외 c 함수 호출하는 경우도 흔함.
SkSLBench.cpp 파일 컴파일 중에 에러가 났는데,
freebsd 에 mallinfo 라는 함수가 없어서 에러가 났음.
그래서 어떻게 했느냐..
#ifdef __FreeBSD__
#include <stdlib.h>
#include <malloc_np.h>
static int64_t heap_bytes_used() {
size_t allocated;
size_t len =
sizeof (allocated);
if (!
mallctl (
"stats.allocated", &allocated, &len,
NULL,
0))
return allocated;
return -1;
}
#else
#include <malloc.h>
static int64_t heap_bytes_used() {
return (
int64_t)
mallinfo().uordblks;
}
#endif요렇게 만들어줬지.
mallctl (
"stats.allocated", &allocated, &len,
NULL,
0) 이것이
mallinfo().uordblks 이걸 의미하는지는 아직 잘 모름.
저 부분은 중요한 부분이 아니라 컴파일 에러 나지 말라고
일단 저렇게 한 거고,
자세한 것은 프비, 리눅이 매뉴얼 봐야됨.
알아야지
중요한내용이고만
멎내