linux kernel 과 gcc 실행시 argument list too long 과의 관계

jmbae940의 이미지

안녕하세요. 저는 어느 한 개발팀에서 개발 서버를 담당하고 있는 초보입니다. ;;

다름이 아니고 gcc를 사용해서 compile 시에 argument list too long 이라는 error 가 발생합니다.

어느 분께 여쭤보니. server의 kernel update를 하면 된다고 하는군요.

현재 사용하고 있는 서버 커널 이미지의 버젼은 2.6.1XX 입니다.

제 생각에는 gcc의 version 만 상관이 있는게 아니가요? argument list too long 과 커널 버젼과의 관계가 무엇인가요??

cinsk의 이미지

한 프로세스에서 받을 수 있는 argument의 길이 및 갯수는 제한되어 있습니다. 커널 설정에 따라 이 크기가 달라질 수 있겠지만, 이 에러가 발생했다고 커널을 바꾸는 건 "배보다 배꼽이 큰" 상황인 것 같군요.

실행 명령에 너무 많은 인자가 전달되어 그런 것이니, find(1), xargs(1) 등을 써서 해당 프로세스에 전달되는 인자 갯수를 줄이세요. 참고로, google에서 ARG_MAX 또는 "arguments too long"으로 검색하면, 원하는 결과가 나올 겁니다.

--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/

dorado2의 이미지

2.6.23 버전 커널부터 해당문제가 해결된 것으로 알고 있습니다.

http://kldp.org/node/85867

관련 이슈에 대한 kldp 게시물 링크도 있네요.

jmbae940의 이미지

답변 감사합니다.

esrevinu의 이미지

linker에 인자를 find나 xargs 등으로 어떻게 넣어야 할지 모르겠습니다.
shared library를 만드는데
/usr/bin/c++ 뒤에 엄청나게 많은 object 파일들이 나열되어 있습니다.
c++ 명령 뒤에 이 모든 object 파일들이 한꺼번에 와야 할 것 같은데
find나 xargs를 쓰는 방법은 object 파일을 한 개 또는 몇 개씩
나눠서 c++ 명령으로 보내는 것으로 알고 있습니다.
커널 버젼은 2.6.9이고 시스템은 제가 손을 댈 수가 없습니다.
linker에 나눠서 보내는 방법이 있는지 옵션을 찾아 봤는데 모르겠습니다.

bushi의 이미지

묶고 싶은 단위로 ar 을 사용해서 묶으세요.
링크 하실 땐 순서가 중요한데, 순서 맞추기 귀찮으면 링크 옵션을 좀 더 주는 귀찮음을 감수하시고요.

[bushi@rose net]$ echo "int print_a(void){printf(\"A\");}" > a.c
[bushi@rose net]$ echo "int print_b(void){printf(\"B\");}" > b.c
[bushi@rose net]$ echo "int print_c(void){printf(\"C\");}" > c.c
[bushi@rose net]$ echo "int print_n(void){printf(\"\n\");}" > n.c
 
[bushi@rose net]$ gcc -o a.o -c a.c
a.c: In function ‘print_a’:
a.c:1: warning: incompatible implicit declaration of built-in function ‘printf’
[bushi@rose net]$ gcc -o b.o -c b.c
b.c: In function ‘print_b’:
b.c:1: warning: incompatible implicit declaration of built-in function ‘printf’
[bushi@rose net]$ gcc -o c.o -c c.c
c.c: In function ‘print_c’:
c.c:1: warning: incompatible implicit declaration of built-in function ‘printf’
[bushi@rose net]$ gcc -o n.o -c n.c
n.c: In function ‘print_n’:
n.c:1: warning: incompatible implicit declaration of built-in function ‘printf’
[bushi@rose net]$
[bushi@rose net]$ ar rcs x1.a a.o b.o
[bushi@rose net]$ ar rcs x2.a c.o n.o
[bushi@rose net]$
[bushi@rose net]$ echo "int main(){print_a();print_b();print_c();print_n();}" > main.c
[bushi@rose net]$ gcc -o main.o -c main.c
[bushi@rose net]$ 
[bushi@rose net]$ gcc -o test x1.a x2.a main.o
main.o: In function `main':
main.c:(.text+0x7): undefined reference to `print_a'
main.c:(.text+0xc): undefined reference to `print_b'
main.c:(.text+0x11): undefined reference to `print_c'
main.c:(.text+0x16): undefined reference to `print_n'
collect2: ld returned 1 exit status
[bushi@rose net]$ 
[bushi@rose net]$ gcc -o test x1.a main.o x2.a
main.o: In function `main':
main.c:(.text+0x7): undefined reference to `print_a'
main.c:(.text+0xc): undefined reference to `print_b'
collect2: ld returned 1 exit status
[bushi@rose net]$ 
[bushi@rose net]$ 
[bushi@rose net]$ gcc -o test main.o x1.a x2.a
[bushi@rose net]$ 
[bushi@rose net]$ ./test
ABC
[bushi@rose net]$
[bushi@rose net]$ rm test
[bushi@rose net]$ 
[bushi@rose net]$ gcc -o test -Wl,--start-group x1.a x2.a main.o -Wl,--end-group 
[bushi@rose net]$ 
[bushi@rose net]$ ./test
ABC
[bushi@rose net]$ 
esrevinu의 이미지

고맙습니다. 그런 방법이 있었네요.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.