NDK compiled C + + compatibility issues Summary collation

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/wenrenwang/article/details/12003671

1.__int64 can't find the symbol

Use int64_t to replace:
1 #if defined (__android__)2typedef int64_t __INT64; 3 #endif

2.<sys/io.h> can't find them.

1 Android does not need to directly reference the file, with the following macro removed can be 2 #if !defined (__apple__) &&!defined (__android__)3 #include <sys/io.h>4  #endif

3.so_nosigpipe can't find them.

So_nosigpipe exists in the Mac, but it doesn't exist in Android. Please use msg_nosignal to replace
1 #if defined (__android__)2#define so_nosigpipe msg_nosignal3#endif 

4.uint64_t, int64_t, uint32_t, int32_t and other similar types cannot be found

Please check your header file contains, put the system's header file before your own header file. Because your own header file has a duplicate type that can be defined, it causes the system header file to fail.

5.s_iread, S_iwrite or __s_iread, __s_iwrite can't find

Please replace it with S_IRUSR and S_IWUSR.

6.pthread_cancel can't find them.

This android is not implemented, there are a number of alternative methods, see in detail: http://bbs.rosoo.net/thread-10289-1-1.html

7.getifaddrs, <ifaddr.h> not found

Android has not been implemented. But thankfully, someone has helped us achieve it. Thank him: Https://github.com/kmackay/android-ifaddrs

8.<sys/statvfs.h> can't find them.

Please use this instead:
1 #if defined (__android__)2 #  include <sys/vfs.h>3#  define Statvfs Statfs4#else5 #  include <sys/statvfs.h>6#endif

Transferred from: http://www.52rd.com/Blog/Detail_RD.Blog_DamonKabo_68286.html

In the process of downloading and compiling Android source code, the problem will be sorted as follows:

One.

frameworks/Base/include/utils/keyedvector.h:193: to: Error: ' Indexofkey ' is not declaredinch  ThisScope, and no declarations were found by Argument-dependent lookup at the point of instantiation [-Fpermissive]frameworks/Base/include/utils/keyedvector.h:193: to: note:declarationsinchDependentBase' Android::keyedvector<android::string8, android::sp<aaptdir> >' is not found by unqualified lookupframeworks/Base/include/utils/keyedvector.h:193: to: Note:use ' This-Indexofkey ' Insteadmake:*** [ out/HOST/LINUX-X86/OBJ/EXECUTABLES/AAPT_INTERMEDIATES/AAPTASSETS.O] Error1

Workaround :

The general cause of this problem is that the compiler does not recognize certain nonconformance code, and the workaround is to add-fpermissive to the appropriate location to mask the compiler's rejection of such code.

Frameworks/base/tools/aapt/android.mk

Add '-fpermissive ' to line 31:
Local_cflags + =-wno-format-y2k-fpermissive

But continue to error: cc1plus:warning:unrecognized command line option "-wno-format-y2k-fpermissive"

Workaround :

This type of error is not found in the required library files:cannot find-lxxxxx , where lxxxxx represents the libxxxxx.so, the cause generally has two aspects:

a) because. So is a temporary build of the file, if the previous file compilation error, libxxxxx.so not generated, will be an error.

b) As a result of the native environment:

1. The system lacks the corresponding library file--download the corresponding library file, Ubuntu is usually installed by command Apt-get install Libxxxxx-dev 2. Version does not correspond to-----------------> ibid. 3.    Library file link Error--------> Locate the link file via the Find or locate directive to see if the link file is correctly pointing to the Lib we want, and if not, modify it with the LN-SF */libxxx.so.x */libxxx.so directive. 4. library file path setting problem------> If it is a problem caused by the path of the library file, you can modify any of the Conf files in the/ETC/LD.SO.CONF.D directory, (you can build the Conf to facilitate identification), write the Lib directory and enter it in the terminal. Ldconfig Update Cache

Three.

Host C + +: Obbtool <= frameworks/base/tools/obbtool/main.cpp
<command-line>:0:0: Error: "_fortify_source" redefined [-werror]
Frameworks/base/tools/obbtool/main.cpp:1:0:note:this is the location of the previous definition
Cc1plus:all warnings being treated as errors
Make: * * * [OUT/HOST/LINUX-X86/OBJ/EXECUTABLES/OBBTOOL_INTERMEDIATES/MAIN.O] Error 1

Workaround :

Because the GCC version is too high, you need to change the GCC version to 4.4.6

sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4

On Ubuntu, change the default GCC and g++ versions to 4.4 using the following command

1.sudo RM/USR/BIN/GCC

2.sudo ln-s/USR/BIN/GCC-4.4/USR/BIN/GCC

Four.

Target thumb C + +: Libmedia <= frameworks/base/media/libmedia/mediascanner.cpp
frameworks/base/media/libmedia/mediascanner.cpp:in function ' bool Android::filematchesextension (const char*, const char*) ':
Frameworks/base/media/libmedia/mediascanner.cpp:84:error:invalid conversion from ' const char* ' to ' char* '
Frameworks/base/media/libmedia/mediascanner.cpp:90:error:invalid conversion from ' const char* ' to ' char* '
Make: * * * [OUT/DEBUG/HOST/LINUX-X86/PR/SIM/OBJ/SHARED_LIBRARIES/LIBMEDIA_INTERMEDIATES/MEDIASCANNER.O] Error 1

Workaround :

Because the GCC4.4 version does not support const char* and char* conversions at compile time, it should be compiled on the other GCC versions. Specific explanations http://gcc.gnu.org/gcc-4.4/porting_to.html

FRAMEWORKS/BASE/MEDIA/LIBMEDIA/MEDIASCANNER.CPP:84&90:

-char*

+const char*

Five.

Development/simulator/app/devicemanager.cpp:8: Fatal error:wx/wxprec.h:no such file or directory
Compilation terminated.
Development/simulator/app/devicewindow.cpp:8: Fatal error:wx/wxprec.h:no such file or directorymake: * * * [out/host/ LINUX-X86/OBJ/EXECUTABLES/SIMULATOR_INTERMEDIATES/DEVICEMANAGER.O] Error 1

ubuntu13.04 cannot support Libwxgkt2.6-dev so you need to install a high version of wx2.8

Workaround:

Apt-file Search Wxprec.h

sudo apt-get install wx2.8
Wx-config--cflags

Six. Synchronizing the internal environment

. build/envsetup.sh
Lunch

Lunch Menu ... pick a combo:
1. Generic-eng
2. Simulator
3. Full_passion-userdebug
4. Full_crespo-userdebug

Choose 2

Make-j4

Transferred from: http://blog.csdn.net/xiaominghimi/article/details/7637530

This article describes some of the details and points to note when adding network communication-related code to COCOS2DX and then compiling it to Android. Not much nonsense, directly into the subject;

1. First introduce the use of Pthread compilation in COCOS2DX should be noted:

Because the NDK explicitly indicates that the Pthread_cancel () function is not supported, the compiler error prompts are as follows:

Solution:

Use Pthread_kill () or return NULL; Two methods to resolve.

The differences are as follows:

Pthread_exit (): You can specify a return value so that other threads get the return value of the thread through the Pthread_join () function;

Return: Use return in the thread function to exit the threads;

It is recommended to return directly to NULL here Himi;

2. Compile prompt cannot find the definition of sockaddr_in and htons, error prompt is as follows:

This problem occurs primarily when the header file is not joined, although the iOS compilation environment does not hold the wrong, but the compilation occurs.

Solution:

In the class that uses these functions, add the following two header files:

[CPP]View Plaincopy
    1. #include "Netdb.h"
    2. #include "Netinet/in.h"



3. The Curl.h header file cannot be found . Note that here is the problem that the header file cannot be found in the compilation, if you are Xcode compilation can not find the head file, please refer to the following blog: (This is explained in the NDK to compile the Android process of such problems in the solution)

"HTTP text of c/s communication interaction" COCOS2DX (Client) uses Curl and jetty (Server) to implement the HTTP communication framework for mobile online games (contains the solution curl.h header file can not find the problem)

Observe the log of errors first:

Solution:

In the class in which you use curl, although you import the Curl class, you must be an include "curl/curl.h" Import! OK, change the following to specify the complete relative path:

[CPP]View Plaincopy
    1. ".. /.. /libs/cocos2dx/platform/third_party/ios/curl/curl.h "

4. Sometimes compile error, wrong hint said Curl_global_init, curl_easy_init, curl_easy_setopt etc. no definition undefined! This problem is caused by not joining the Curl associated LIB package;

Solution:

Modify the. mk file under HelloWorld under JNI, the entire path is as follows:

Your project//android/jni/helloworld/android.mk

Open the entire MK file and find the following:

Change to the following:

In fact, it is added two words! but be careful!

you look closely at the first sentence to add the middle of the next sentence , before it is " : = " is now "+=" Be sure to note that this problem plagued Himi for several hours =.

OK, basically these are enough to solve the problem ~

NDK compiled C + + compatibility issues Summary collation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.