Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts

Saturday, July 19, 2014

How to use the same C++ code for Android and iOS?

Best tutorial on using C++ code with iOS and Android


Please read this wonderful StackOverflow post:

Sunday, July 13, 2014

10 Rules for writing portable software!

I recently came across a good article about writing portable software with C/C++.


Brian's 10 rules for how to write cross platform software:

  1. Don't port 
  2. Factor out the GUI 
  3. Use standard 'C' types 
  4. Use only built in #ifdef compiler flags 
  5. Develop cross-platform base libraries
  6. Use UTF-8 for all APIs 
  7. Don't use 4rd party 'Application Frameworks' 
  8. Raw source builds on all platforms 
  9. All programmers compile on all platforms 
  10. Fire those that can't follow these rules

Source:

Friday, December 16, 2011

How to use libcurl in C/C++

libcurl
Newer languages such as Java and newer scripting languages such as Python come with good libraries to download files and do online work. A good way to download files using C/C++ is to download and install the libcurl library.
First run 'curl-config --libs' to see if you have the library '-libcurl'
search for the package: 'apt-cache search libcurl'
install the package: 'sudo apt-get install libcurl4-nss-dev'
check to see if you have the package again
Next, go to http://curl.haxx.se/libcurl/c/simple.html. Copy and paste the code, save as 'simple.c' Change the "http://example.com" to something you want.
Compile your code: 'gcc simple.c -lcurl -o simple.out'
Run the code: './simple.out'

Output of (http://www.google.com/):
http://curl.haxx.se/libcurl/c/simple.html

Friday, September 23, 2011

How to fix 'for' loop initial declarations are only allowed in C99 mode in Eclipse

For loop problem
Once again, programming in C using Eclipse in Linux is great, however when using "for" loops I get this error:
'for' loop initial declarations are only allowed in C99 mode
After a little bit of research, in Eclipse, go to Project > Properties > C/C++ Build > Settings > GCC C Compiler > Miscellaneous > add "-std=c99" to the "Linker Flags" text field.
http://www.eclipse.org/forums/index.php?t=msg&goto=212981&

How to fix undefined reference to `sqrt' in Eclipse

Math.h problem
Programming in C using Eclipse in Linux is great, however when i added variables that were doubles into the "sqrt" function from the "math.h" library there was a problem that came up.
undefined reference to `sqrt'
After a little bit of research, in Eclipse, go to Project > Properties > C/C++ Build > Settings > GCC C Linker > Miscellaneous > add "-lm" to the "Linker Flags" text field. That way it is properly linked to the project.
http://cboard.cprogramming.com/c-programming/88943-undefined-reference-sqrt.html

Monday, May 30, 2011

How to write HelloWorld in C?


HelloWorld.c

#include <stdio.h>
int main() {
  printf("Hello world!\n");
}