Data: 2009-04-21 20:23:09
ziemianp | Kompilacja z użyciem biblioteki curl pod linuksem
Witam wszystkich!
Mam problem z kompilacją programu, który używa biblioteki curl. Jest to przykład z oficjalnej strony projektu:
#include <stdio.h> #include <curl/curl.h>
int main(void) { CURL *curl; CURLcode res;
curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); res = curl_easy_perform(curl);
/* always cleanup */ curl_easy_cleanup(curl); } return 0; }
Mam zainstalowany pakiet curl. Podczas kompilacji, którą przeprowadzam tak: g++ nazwa.cpp -o prog
dostaje komunikaty:
simple.cpp:2:23: error: curl/curl.h: Nie ma takiego pliku ani katalogu simple.cpp: In function ‘int main()’: simple.cpp:6: error: ‘CURL’ was not declared in this scope simple.cpp:6: error: ‘curl’ was not declared in this scope simple.cpp:7: error: ‘CURLcode’ was not declared in this scope simple.cpp:7: error: expected `;' before ‘res’ simple.cpp:9: error: ‘curl_easy_init’ was not declared in this scope simple.cpp:11: error: ‘CURLOPT_URL’ was not declared in this scope simple.cpp:11: error: ‘curl_easy_setopt’ was not declared in this scope simple.cpp:12: error: ‘res’ was not declared in this scope simple.cpp:12: error: ‘curl_easy_perform’ was not declared in this scope simple.cpp:15: error: ‘curl_easy_cleanup’ was not declared in this scope
Niby wszystko jasne, ale linuksa mam od kilku dni i nie wiem co zrobić. Pakiety curl mam zainstalowane. Może trzeba użyć jakiś flag, ale nie wiem jak je wydobyć.
Mam Debiana. Proszę o jakieś wskazówki. Z tego co widzę na google, to generalnie nie ma takich problemów..
| Data: 2009-04-21 20:40:37
DeBugger |
Poszukaj pakietów zawierających: curl i dev. Hmm: Może być coś takiego:
-libcurl-dev; | Data: 2009-04-21 21:01:59
ziemianp |
Dodałem pakiety libcurl3-dbg, libcurl4-gnutls-dev. Czyli okazuje się, że nie dodałem wszystkiego - wcześniej dodałem pakiet curl. Jest pewien postęp, ale jeszcze czegoś brakuje:
g++ simple.cpp -o test /tmp/ccs3zryK.o: In function `main': simple.cpp:(.text+0x12): undefined reference to `curl_easy_init' simple.cpp:(.text+0x36): undefined reference to `curl_easy_setopt' simple.cpp:(.text+0x41): undefined reference to `curl_easy_perform' simple.cpp:(.text+0x4f): undefined reference to `curl_easy_cleanup' collect2: ld returned 1 exit status
może jeszcze powinienem coś dodać? | Data: 2009-04-21 21:02:12
DeBugger |
Zapomniałem o linkowaniu. Dodaj jeszcze:
-lcurl Przy kompilacji.
| Data: 2009-04-21 21:06:10
ziemianp |
Dzięki! Poszło, a to końcówka wykonania na dowód:
<center> <a class="bottomad" href="http://www.easyalgo.com/eaupload.aspx" title="Asp.net upload component">File upload with ASP.NET</a> </center> <!-- last-line-in-body --> </BODY> </HTML>
czyli podsumowując, dodałem te dwa pakiety i potem skompilowałem używając: g++ simple.cpp -lcurl -o test
Pozdrawiam!
| |
| Statystyki tematu | Ostatnio przeczytali |
|---|
| Czytało użytkowników: | 29 | Gabes, markon, malan, BlackDante, nehemaah, Viper, Carlosss, kampar, skovv, Dante, Skala, geftus, Fanael, pixelmaster, driver1995, DeBugger, WunM, pekfos, Mareczek, Pietrzuch, krdk, Proxym, Onizuka, setless, n3t_b0y, macko, Piotr Szawdyński, ziemianp | | Przeczytało użytkowników: | 28 | | Czytało osób ogólnie: | 69 | | Przeczytało osób ogólnie: | 66 |
| Ostatnia Aktualizacja| 2010-09-01 19:27:34 (6 dni temu) | |
| Ostatnio aktywni |
|---|
| fish13 | 3 godz | | wiewiorka | 9 godz | | Koni | 10 godz | | BuZuz | 10 godz | | Prezmen | 12 godz | | trupank | 12 godz | | szczgl | 14 godz | | filipesq | 14 godz | | KRIIS551 | 16 godz | | kuba1817 | 16 godz | | extra2 | 17 godz | | pixelmaster | 18 godz |
|