ESP32(esp-idf) iconv 함수 사용방법!!

익명 사용자의 이미지

ESP32(esp-idf)에서 한글 와이파이 ssid를 인식하기위해 iconv함수를 이용해 EUC-KR -> UTF8로 변환하려고 하는데 ㅠㅠ 계속 Undefined reference 에러가 발생합니다... 분명히 헤더파일도 추가했는데 왜이러는 걸까요?.. 혹시 다른 경로를 추가해야하는건가요? 도와주세요

int ret;
iconv_t it;
char ksc_buf[1024];
strcpy(ksc_buf, data);
 
// KSC(완성형) 코드를 UTF(유니코드)로 변환하면 원래 크기보다 커지므로 크게~
char utf_buf[1024] = {0x00, };
size_t in_size, out_size;
 
memset(utf_buf, '\0', 1024);
 
// 어떤 시스템에서는 char** 가 아니라 const char** 인 경우도 있음
char *input_buf_ptr = ksc_buf;
char *output_buf_ptr = utf_buf;
 
in_size = strlen(ksc_buf);
out_size = sizeof(utf_buf);
 
it = iconv_open("UTF-8", "EUC-KR"); // EUC-KR을 UTF-8로
ret = iconv(it, &input_buf_ptr, &in_size, &output_buf_ptr, &out_size);
 
if (ret < 0)
{
    printf("ret : %d, errno : %d\n", ret, errno);
    return(-1);
}
else
{
    printf("[%s](%d) => [%s][(%d)\n",
        ksc_buf, in_size, utf_buf, out_size);
}
 
iconv_close(it);

c : / msys32 / opt / xtensa-esp32-elf / bin /../ lib / gcc / xtensa-esp32-elf / 8.2.0 /../../../../ xtensa-esp32-elf / bin / ld.exe : C : / msys32 / home / esp / blufi / build / main \ libmain.a (blufi_example_main.o) :(. literal.Change + 0x18) : iconv_open' c:/msys32/opt/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/msys32/home/esp/blufi/build/main\libmain.a(blufi_example_main.o):(.literal.Change+0x1c): undefined reference to iconv에 대한 정의되지 않은 참조
c : / msys32 / opt /xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe : C : / msys32 / home / esp / blufi / build / main \ libmain.a (blufi_example_main.o) :(. literal.Change + 0x20) : iconv_close' c:/msys32/opt/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/msys32/home/esp/blufi/build/main\libmain.a(blufi_example_main.o): in function 변경에 대한 정의되지 않은 참조 ':
C : / msys32 / home / esp / blufi / main / blufi_example_main.c : 534 : iconv_open' c:/msys32/opt/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/msys32/home/esp/blufi/main/blufi_example_main.c:535: undefined reference to iconv '
c : / msys32 / opt / xtensa-esp32-elf / bin /../ lib / gcc / xtensa-esp32-elf / 8.2.0 /../.에 대한 정의되지 않은 참조 . /../../xtensa-esp32-elf/bin/ld.exe : C : /msys32/home/esp/blufi/main/blufi_example_main.c : 544 :`iconv_close '에 대한 정의되지 않은 참조
collect2.exe : 오류 : ld가 1 개의 종료 상태
작성을 리턴했습니다 . *** [C : /msys32/home/esp/esp-idf/make/project.mk : 523 : /home/esp/blufi/build/blufi_demo.elf ] 오류
익명 사용자의 이미지

C/C++에서 외부 라이브러리를 쓸 땐 헤더를 include하는 것만으론 충분하지 않습니다. 헤더 파일은 대개 함수 선언 정도만 가지고 있기 때문이지요.

-l 옵션으로 링크할 라이브러리를 지정해 줘야 합니다. 상황에 따라 -lc 혹은 -liconv를 써야 한다는군요.

김정균의 이미지

gnu libc(glibc) 의 경우에는 iconv 를 포함하고 있기 때문에 별도로 -liconv 를 해 줄 필요가 없습니다. -lc 가 libc 를 link 하라는 의미인데.. 이건 기본이라 주나 안주나 별로 의미가.. 없죠. 그리고 -lc 를 언급한 이유가 libc 에 iconv 가 포함되어 있는 경우를 말합니다.

gnu libc 를 사용하지 않는 시스템에서는 libiconv 를 설치 해 주어야 하고, -liconv 로 compile 시에 link 해 주어야 합니다.

원 질문의 상황을 보면 windows 에서 빌드를 하는 것이기 때문에 libiconv 설치가 필요하고 익명사용자님의 언급대로 compile 시에 -liconv 로 link를 해 주어야 합니다.

아의 이미지

code block은 몰랐습니다. ㅠㅠ 죄송해요
답변자님 말씀대로 libiconv 설치를 하려고했는데 이미 usr include 안에 iconv.h가 포함되어있습니다. 이럴경우에는 패스지정을 하면 되는건가요? 그렇다면 어떻게 해야하나요?.... 초보적인 질문이라 정말 죄송합니다. msys32를 처음 써봐서요..

김정균의 이미지

iconv.h 는 단순히 iconv api 를 declare 해 놓은 파일일 뿐 입니다. 실제 object 들은 libiconv.dll 또는 libiconv.a 에 들어있고, compile 시에 linking 을 해 주어야 합니다. 보통 gnu c 에서는 -l 옵션으로 linking 을 하는데, 사용하시는 개발 환경에서는 어떻게 하는지 저도 모르겠네요. 어찌 되었든, *.mk 파일에서 iconv 에 대한 내용이 있어야 한다는 얘기 입니다.

http://gnuwin32.sourceforge.net/packages/libiconv.htm

김정균의 이미지

코드를 입력 할 때는 제발 code block 을 사용해 주세요.

<code lang="c">
code code code code
</code>

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.