fann95 / C4droid-Shell

Command line shell,tools and libraries for C4droid.
33 stars 10 forks source link

Code uses libcurl,compile errors #4

Open shifaz opened 9 years ago

shifaz commented 9 years ago

After that I tried compiling sample curl code, its giving the following error. Please help.

/storage/.../../C4droid_EXT $ gcc -o connect simple_curl.c -lcurl -I include -L lib
/data/data/com.n0n3m4.droidc/files/gcc/bin/../lib/gcc/arm-linux-androideabi/4.9.1/../../../../arm-linux-androideabi/bin/ld: warning: libz.so, needed by lib/libcurl.so, not found (try using -rpath or -rpath-link)
/data/data/com.n0n3m4.droidc/files/gcc/bin/../lib/gcc/arm-linux-androideabi/4.9.1/../../../../arm-linux-androideabi/bin/ld: warning: libcrypto.so.5, needed by lib/libcurl.so, not found (try using -rpath or -rpath-link)
/data/data/com.n0n3m4.droidc/files/gcc/bin/../lib/gcc/arm-linux-androideabi/4.9.1/../../../../arm-linux-androideabi/bin/ld: warning: libssl.so.5, needed by lib/libcurl.so, not found (try using -rpath or -rpath-link)
/data/data/com.n0n3m4.droidc/files/gcc/bin/../lib/gcc/arm-linux-androideabi/4.9.1/../../../../arm-linux-androideabi/bin/ld: warning: libssh2.so.1, needed by lib/libcurl.so, not found (try using -rpath or -rpath-link)
/data/data/com.n0n3m4.droidc/files/gcc/bin/../lib/gcc/arm-linux-androideabi/4.9.1/../../../../arm-linux-androideabi/bin/ld: warning: libm.so, needed by lib/libcurl.so, not found (try using -rpath or -rpath-link)
lib/libcurl.so: undefined reference to `RAND_load_file'
lib/libcurl.so: undefined reference to `UI_method_set_closer'
lib/libcurl.so: undefined reference to `libssh2_knownhost_free'
lib/libcurl.so: undefined reference to `libssh2_knownhost_add'
lib/libcurl.so: undefined reference to `SSL_CTX_use_certificate'
lib/libcurl.so: undefined reference to `UI_method_get_reader'
lib/libcurl.so: undefined reference to `X509_load_crl_file'
lib/libcurl.so: undefined reference to `ENGINE_load_private_key'
lib/libcurl.so: undefined reference to `libssh2_knownhost_writefile'
lib/libcurl.so: undefined reference to `libssh2_sftp_close_handle'
lib/libcurl.so: undefined reference to `SSL_set_fd'
lib/libcurl.so: undefined reference to `libssh2_session_free'
lib/libcurl.so: undefined reference to `SSL_set_connect_state'
lib/libcurl.so: undefined reference to `SSL_CTX_free'
lib/libcurl.so: undefined reference to `ENGINE_get_first'
lib/libcurl.so: undefined reference to `UI_method_set_opener'
lib/libcurl.so: undefined reference to `X509_free'
lib/libcurl.so: undefined reference to `SSL_shutdown'
lib/libcurl.so: undefined reference to `zlibVersion'
lib/libcurl.so: undefined reference to `ENGINE_finish'
lib/libcurl.so: undefined reference to `BN_bin2bn'
lib/libcurl.so: undefined reference to `SSL_CTX_callback_ctrl'
lib/libcurl.so: undefined reference to `libssh2_sftp_stat_ex'
lib/libcurl.so: undefined reference to `ERR_error_string_n'
lib/libcurl.so: undefined reference to `ENGINE_set_default'
lib/libcurl.so: undefined reference to `ENGINE_free'
lib/libcurl.so: undefined reference to `SSL_CTX_set_default_verify_paths'
lib/libcurl.so: undefined reference to `BN_CTX_new'
lib/libcurl.so: undefined reference to `BN_value_one'
lib/libcurl.so: undefined reference to `SSL_get_error'
lib/libcurl.so: undefined reference to `libssh2_scp_send64'
lib/libcurl.so: undefined reference to `DES_set_odd_parity'
lib/libcurl.so: undefined reference to `libssh2_sftp_write'
lib/libcurl.so: undefined reference to `inflate'
lib/libcurl.so: undefined reference to `BN_bn2bin'
lib/libcurl.so: undefined reference to `RAND_add'
lib/libcurl.so: undefined reference to `UI_method_get_opener'
lib/libcurl.so: undefined reference to `sk_num'
lib/libcurl.so: undefined reference to `SSL_get_session'
lib/libcurl.so: undefined reference to `SSL_peek'
lib/libcurl.so: undefined reference to `SSL_get_shutdown'
lib/libcurl.so: undefined reference to `HMAC_Final'
lib/libcurl.so: undefined reference to `SSL_read'
lib/libcurl.so: undefined reference to `HMAC_Init_ex'
lib/libcurl.so: undefined reference to `libssh2_sftp_mkdir_ex'
lib/libcurl.so: undefined reference to `SSL_new'
lib/libcurl.so: undefined reference to `SSL_CTX_new'
lib/libcurl.so: undefined reference to `libssh2_sftp_open_ex'
lib/libcurl.so: undefined reference to `libssh2_sftp_shutdown'
lib/libcurl.so: undefined reference to `ENGINE_ctrl_cmd'
lib/libcurl.so: undefined reference to `UI_OpenSSL'
lib/libcurl.so: undefined reference to `SSL_library_init'
lib/libcurl.so: undefined reference to `UI_set_result'
lib/libcurl.so: undefined reference to `ENGINE_cleanup'
lib/libcurl.so: undefined reference to `OPENSSL_add_all_algorithms_noconf'
lib/libcurl.so: undefined reference to `SSL_CTX_set_default_passwd_cb'
lib/libcurl.so: undefined reference to `RC4_set_key'
lib/libcurl.so: undefined reference to `libssh2_session_startup'
lib/libcurl.so: undefined reference to `libssh2_session_block_directions'
lib/libcurl.so: undefined reference to `ERR_peek_error'
lib/libcurl.so: undefined reference to `libssh2_agent_userauth'
lib/libcurl.so: undefined reference to `libssh2_channel_send_eof'
lib/libcurl.so: undefined reference to `PKCS12_free'
lib/libcurl.so: undefined reference to `X509_get_pubkey'
lib/libcurl.so: undefined reference to `DH_generate_key'
lib/libcurl.so: undefined reference to `SSL_CTX_load_verify_locations'
lib/libcurl.so: undefined reference to `BN_mod_exp'
lib/libcurl.so: undefined reference to `BN_hex2bn'
lib/libcurl.so: undefined reference to `SSL_pending'
lib/libcurl.so: undefined reference to `sk_pop_free'
lib/libcurl.so: undefined reference to `SSL_CTX_set_verify'
lib/libcurl.so: undefined reference to `sk_pop'
lib/libcurl.so: undefined reference to `libssh2_session_last_errno'
lib/libcurl.so: undefined reference to `UI_get_input_flags'
lib/libcurl.so: undefined reference to `PKCS12_parse'
lib/libcurl.so: undefined reference to `BN_set_word'
lib/libcurl.so: undefined reference to `X509_verify_cert_error_string'
lib/libcurl.so: undefined reference to `BN_num_bits'
lib/libcurl.so: undefined reference to `SSL_get_privatekey'
lib/libcurl.so: undefined reference to `libssh2_session_last_error'
lib/libcurl.so: undefined reference to `libssh2_session_hostkey'
lib/libcurl.so: undefined reference to `ENGINE_load_builtin_engines'
lib/libcurl.so: undefined reference to `OpenSSL_add_all_digests'
lib/libcurl.so: undefined reference to `MD4_Update'
lib/libcurl.so: undefined reference to `BIO_free'
lib/libcurl.so: undefined reference to `inflateInit_'
lib/libcurl.so: undefined reference to `X509_NAME_print_ex'
lib/libcurl.so: undefined reference to `DH_new'
lib/libcurl.so: undefined reference to `SSLeay'
lib/libcurl.so: undefined reference to `RC4'
lib/libcurl.so: undefined reference to `libssh2_agent_free'
lib/libcurl.so: undefined reference to `DH_compute_key'
lib/libcurl.so: undefined reference to `BIO_ctrl'
lib/libcurl.so: undefined reference to `RAND_egd'
lib/libcurl.so: undefined reference to `libssh2_sftp_unlink_ex'
lib/libcurl.so: undefined reference to `SSL_CTX_set_srp_username'
lib/libcurl.so: undefined reference to `SSL_SESSION_free'
lib/libcurl.so: undefined reference to `CRYPTO_free'
lib/libcurl.so: undefined reference to `BN_sub_word'
lib/libcurl.so: undefined reference to `ENGINE_init'
lib/libcurl.so: undefined reference to `SSL_load_error_strings'
lib/libcurl.so: undefined reference to `SSL_get_certificate'
lib/libcurl.so: undefined reference to `RAND_file_name'
lib/libcurl.so: undefined reference to `i2t_ASN1_OBJECT'
lib/libcurl.so: undefined reference to `libssh2_agent_disconnect'
lib/libcurl.so: undefined reference to `ASN1_STRING_print'
lib/libcurl.so: undefined reference to `SSL_CTX_set_cipher_list'
lib/libcurl.so: undefined reference to `MD4_Final'
lib/libcurl.so: undefined reference to `libssh2_sftp_rename_ex'
lib/libcurl.so: undefined reference to `SSL_CIPHER_get_name'
lib/libcurl.so: undefined reference to `libssh2_userauth_password_ex'
lib/libcurl.so: undefined reference to `BIO_new'
lib/libcurl.so: undefined reference to `SSLv23_client_method'
lib/libcurl.so: undefined reference to `libssh2_sftp_symlink_ex'
lib/libcurl.so: undefined reference to `sk_value'
lib/libcurl.so: undefined reference to `X509_EXTENSION_get_critical'
lib/libcurl.so: undefined reference to `X509_NAME_get_index_by_NID'
lib/libcurl.so: undefined reference to `RAND_status'
lib/libcurl.so: undefined reference to `libssh2_sftp_read'
lib/libcurl.so: undefined reference to `CRYPTO_cleanup_all_ex_data'
lib/libcurl.so: undefined reference to `EVP_PKEY_copy_parameters'
lib/libcurl.so: undefined reference to `X509_get_subject_name'
lib/libcurl.so: undefined reference to `libssh2_channel_wait_eof'
lib/libcurl.so: undefined reference to `libssh2_hostkey_hash'
lib/libcurl.so: undefined reference to `ENGI
fann95 commented 9 years ago

you need to read http://curl.haxx.se/libcurl/using/curl-config.html if your code uses libcurl try it:

$ `curl-config --cc --cflags` ${CFLAGS} -o example example.c `curl-config --libs` ${LDFLAGS}

OR:

$ gcc `curl-config --cflags` ${CFLAGS} -o example example.c `curl-config --libs` ${LDFLAGS}
shifaz commented 9 years ago

Did as you have suggested. Its still showing errors about missing libs.

/storage/.../../C4droid_EXT $ arm-linux-androideabi-gcc -I/mnt/sdcard/C4droid_EXT/include -o example simple_curl.c -L/mnt/sdcard/C4droid_EXT/lib -lcurl -lssh2 -lssl -lcrypto -lz
/data/data/com.n0n3m4.droidc/files/gcc/bin/../lib/gcc/arm-linux-androideabi/4.9.1/../../../../arm-linux-androideabi/bin/ld: warning: libm.so, needed by /mnt/sdcard/C4droid_EXT/lib/libcurl.so, not found (try using -rpath or -rpath-link)
/data/data/com.n0n3m4.droidc/files/gcc/bin/../lib/gcc/arm-linux-androideabi/4.9.1/../../../../arm-linux-androideabi/bin/ld: warning: libstdc++.so, needed by /mnt/sdcard/C4droid_EXT/lib/libssl.so, not found (try using -rpath or -rpath-link)
/storage/.../../C4droid_EXT $
fann95 commented 9 years ago

Because you are trying to compile without flags ${CFLAGS} and ${LDFLAGS} ,just add the flags, as I wrote above.

shifaz commented 9 years ago

Thanks a lot for the help. Really appreciate it.

I got it to compile, but I also get an error saying Failed to copy file when compiled from C4droid using a Makefile.

Because of the permission issues Im unable to execute the binary using any Terminal App.

If you can help, my question is, will it be possible to embed the binary in a Activity just like the hello world example supplied with C4droid.

fann95 commented 9 years ago

You have 'Note 4' with android 5, right? С4droid-Shell not fully compatible with Android 5. I'm not sure, but I think you need to compile with additional flags -fPIE -pie like so:

$ gcc `curl-config --cflags` ${CFLAGS}  -fPIE -pie -o example example.c `curl-config --libs` ${LDFLAGS}

maybe then you will be able to execute the binary. To answer your question: libcurl-code to be compiled using C4droid-Shell is not static and will only work in the C4droid-Shell P.S. Devices with the android 5 have enough memory to install Linux, there is a need-to C4droid-Shell?

Randl commented 9 years ago

I have similar error:

export PATH=/busybox-virtual:/data/data/com.n0n3m4.droidc/files/:/data/data/com.n0n3m4.droidc/files/gcc/bin:/data/data/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/bin/:$PATH
export CC="arm-linux-androideabi-gcc  -I/data/data/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/include/ncurses"
export CXX="arm-linux-androideabi-g++  -I/data/data/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/include/ncurses"
export SHELL="/data/data/com.n0n3m4.droidc/files/busybox sh"
cd "/storage/emulated/0/Work/stocks/"
make CC="$CC" CXX="$CXX" SHELL="$SHELL"
echo "errorcode:$?"
echo "exit""term"
exit
/ $ export PATH=/busybox-virtual:/data/data/com.n0n3m4.droidc/files/:/data/data/com.n0n3m4.droidc/files/gcc/bin:/data/data/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/bin/:$PATH
/ $ export CC="arm-linux-androideabi-gcc  -I/data/data/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/include/ncurses"
/ $ export CXX="arm-linux-androideabi-g++  -I/data/data/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/include/ncurses"
/ $ export SHELL="/data/data/com.n0n3m4.droidc/files/busybox sh"
/ $ cd "/storage/emulated/0/Work/stocks/"
/storage/emulated/0/Work/stocks $ make CC="$CC" CXX="$CXX" SHELL="$SHELL"
mkdir -p ./bin/
arm-linux-androideabi-g++  -I/data/data/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/include/ncurses -I/mnt/sdcard/C4droid_EXT/include main.cpp download.cpp -L/mnt/sdcard/C4droid_EXT/lib  -Wall -Wextra -pedantic -O3 -std=c++11  -o ./bin/bot -lcurl -lssh2 -lssl -lcrypto -lz
/data/data/com.n0n3m4.droidc/files/gcc/bin/../lib/gcc/arm-linux-androideabi/4.9.1/../../../../arm-linux-androideabi/bin/ld: warning: libstdc++.so, needed by /mnt/sdcard/C4droid_EXT/lib/libssl.so, not found (try using -rpath or -rpath-link)
/storage/emulated/0/Work/stocks $ echo "errorcode:$?"
errorcode:0
/storage/emulated/0/Work/stocks $ echo "exit""term"
exitterm

I found only libstdc++.a in c4droid folder.

fann95 commented 9 years ago

you need to add flag -Wl,-allow-shlib-undefined ( -lcurl -lssh2 -lssl -lcrypto -lz -Wl,-allow-shlib-undefined)

Or simply:

`curl-config --libs` ${LDFLAGS}
Randl commented 9 years ago

ok, now I get

CANNOT LINK EXECUTABLE: could not load library "libcurl.so.5" needed by "/data/data/com.n0n3m4.droidc/files/temp"; caused by library "libcurl.so.5" not found

at the memnent it starts. At least it's compiling now.

fann95 commented 9 years ago

simply add -L/data/data/com.n0n3m4.droidc/usr/lib P.S. all you need is a ${CFLAGS} and ${LDFLAGS}.

Randl commented 9 years ago

It is added. And the file is there.

fann95 commented 9 years ago

if you are trying to compile something in the C4droid without using C4droid-Shell, but using his library, you should do it with -I/sdcard/C4droid_EXT/include -I/data/data/com.n0n3m4.droidc/usr/include and with -L/data/data/com.n0n3m4.droidc/usr/lib -L/mnt/sdcard/C4droid_EXT/lib
and redefine variables LD_LIBRARY_PATH like so:

export LD_LIBRARY_PATH="/data/data/com.n0n3m4.droidc/usr/lib:/vendor/lib:/system/lib"

may have to change other variables all environment variables can be found in c4dsh.c or in /data/data/com.n0n3m4.droidc/files/.C4dENV when compiling with the C4droid-Shell environment variables are already set,only need to use ${CFLAGS} and ${LDFLAGS} flags