저는 Mac에 있는데 gcc
과 gmp
부터 homebrew
까지 설치했습니다. 내가 g++ test.cpp -lgmpxx -lgmp
를하려고하면 그것은 그래서 g++ test.cpp -lgmpxx -lgmp -I/usr/local/include/
시도했습니다C++ gmp and homebrew
test.cpp:9:19: fatal error: gmpxx.h: No such file or directory
#include <gmpxx.h>
^
compilation terminated.
을 불평, 모든
#include <iostream>
#include <gmpxx.h>
using namespace std;
int
main (void)
{
mpz_class a, b, c;
a = 1234;
b = "-5678";
c = a+b;
cout << "sum is " << c << "\n";
cout << "absolute value is " << abs(c) << "\n";
return 0;
}
첫째 :
내가 here에서 간단한 예를 시도했습니다 내 설치를 테스트하려면
ld: library not found for -lgmpxx
collect2: error: ld returned 1 exit status
그렇다면을 시도했습니다.
Undefined symbols for architecture x86_64:
"operator<<(std::basic_ostream<char, std::char_traits<char> >&, __mpz_struct const*)", referenced from:
std::basic_ostream<char, std::char_traits<char> >& operator<< <__mpz_struct [1], __mpz_struct [1]>(std::basic_ostream<char, std::char_traits<char> >&, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&) in ccPugkZ3.o
std::basic_ostream<char, std::char_traits<char> >& operator<< <__mpz_struct [1], __gmp_unary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, __gmp_abs_function> >(std::basic_ostream<char, std::char_traits<char> >&, __gmp_expr<__mpz_struct [1], __gmp_unary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, __gmp_abs_function> > const&) in ccPugkZ3.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
재미있는 것은 내가 cout
과 함께 줄을 주석하고 시도하는 경우 g++ test.cpp -lgmpxx -lgmp -I/usr/local/include/ -L/usr/local/lib/ && ./a.out
는 불만이 없다는 것입니다. 특히 c = a+b;
줄은 주석 처리 할 필요가 없었으므로 어떤 일이 벌어지고있는 것처럼 느껴집니다.
무엇이 누락 되었습니까? 샘플 코드를 컴파일하려면 어떻게해야합니까?
편집 :
내가 제대로 오류 메시지를 이해하고있는 경우 @Will의 제안에 따라, 나는g++ test.cpp -lgmpxx -lgmp -I/usr/local/include/ -L/usr/local/lib/ -m32
ld: warning: ld: warning: ignoring file /usr/local/lib//libgmpxx.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib//libgmpxx.dylibignoring file /usr/local/lib//libgmp.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib//libgmp.dylib
Undefined symbols for architecture i386:
"operator<<(std::basic_ostream<char, std::char_traits<char> >&, __mpz_struct const*)", referenced from:
std::basic_ostream<char, std::char_traits<char> >& operator<< <__mpz_struct [1], __mpz_struct [1]>(std::basic_ostream<char, std::char_traits<char> >&, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&) in ccrPv2wC.o
std::basic_ostream<char, std::char_traits<char> >& operator<< <__mpz_struct [1], __gmp_unary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, __gmp_abs_function> >(std::basic_ostream<char, std::char_traits<char> >&, __gmp_expr<__mpz_struct [1], __gmp_unary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, __gmp_abs_function> > const&) in ccrPv2wC.o
"___gmpz_abs", referenced from:
__gmp_abs_function::eval(__mpz_struct*, __mpz_struct const*) in ccrPv2wC.o
"___gmpz_add", referenced from:
__gmp_binary_plus::eval(__mpz_struct*, __mpz_struct const*, __mpz_struct const*) in ccrPv2wC.o
"___gmpz_clear", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr() in ccrPv2wC.o
"___gmpz_init", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr() in ccrPv2wC.o
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr<__gmp_unary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, __gmp_abs_function> >(__gmp_expr<__mpz_struct [1], __gmp_unary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, __gmp_abs_function> > const&) in ccrPv2wC.o
"___gmpz_set_si", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::assign_si(long) in ccrPv2wC.o
"___gmpz_set_str", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::operator=(char const*) in ccrPv2wC.o
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status
시도했습니다
로,이 라이브러리는 실제로 64을 위해 만들어진 것 같다 심지어 mpz_class a, b, c
선언도 -m32
으로 컴파일되지 않습니다.
스위치'도움이 -m32' 추가합니까? 나 자신을 테스트하는 환경이 없지만 32 비트 libs를 설치 한 것일 수 있습니까? – Will
@ 윌 제안을 주셔서 감사합니다,하지만 불행히도 스위치 문제를 해결하지 않는 것. 원본 게시물을 수정하여 오류 메시지를 게시했습니다. – math4tots
아마도 라이브러리 이름 앞에 * 링크 경로를 넣으시겠습니까? 'g ++ -I/usr/local/include/-L/usr/local/lib/-lgmpxx -lgmp test.cpp' (아직도 전화에서 추측) – Will