C Headers (GCC) - header

I am trying to compile some scripts from exploit-db by using GCC (Linux Debian), and when I issue the gcc command to compile the code (gcc -o test test.c) I'm getting a message that says that the files "linux/linkage.h" and "asm/page.h" could not be found.
When I issued a command $ locate linkage.h, I found that these files are in /usr/src/linux-headers-4.3.0-kali1-common/include/linux/linkage.h and /usr/src/linux-headers-4.3.0-kali1-common/include/asm/page.h respectively.
Is there any way to tell GCC to consider this path or maybe change the standard path?
Below you can find a few lines of the code that I am trying to compile.
/*
* Linux kernel 2.4 uselib() privilege elevation exploit.
*
* original exploit source from http://isec.pl
* reference: http://isec.pl/vulnerabilities/isec-0021-uselib.txt
*
* I modified the Paul Starzetz's exploit, made it more possible
* to race successfully. The exploit still works only on 2.4 series.
* It should be also works on 2.4 SMP, but not easy.
*
* thx newbug.
*
* Tim Hsu <timhsu at chroot.org> Jan 2005.
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sched.h>
#include <syscall.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/sysinfo.h>
#include <linux/elf.h>
#include <linux/linkage.h>
#include <asm/page.h>
#include <asm/ldt.h>
#include <asm/segment.h>
#define str(s) #s
#define xstr(s) str(s)

Use the include flag,
gcc -I"/usr/src/linux-headers-4.3.0-kali1-common/include/" -o test test.c

Related

"config.h" used by but not bundled with libxml

libxml uses the following line of code in libxml.h but it doesn't come bundled with libxml.
#include "config.h"
I'm trying to use XMPPFramework for Objective-C, in Swift. The XMPPFramework has libxml as a dependency.
You could try including these:
#include <stdio.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
As found on:
http://wiki.xmlsoft.org/The_libxml2_Library#Installing

How to build both a library and a test executable in the same Eclipse/CDT project?

I have built a shared library under Eclipse/CDT in C++. To manage my projects tests, I would like to have in the same project the library and an executable for running tests on the library.
How can I do that please ?
For the library itself, I have standard build settings : a Debug and a Release target, with the -fPIC compile option, an artifact type Shared Library, extension so and prefix lib, and the -share linker option.
For the test program, I have added in the same project a main.cpp file:
#ifdef TEST_
#include <cstdlib>
#include <iostream>
#include "config.h"
using namespace std;
int main(int argc, char **argv) {
cout << "Test for project utils" << endl;
return 0;
}
#endif /* TEST_ */
I have added a specific Test target copied from the DEBUG one and adapted for standard executable build settings : suppress the -fPIC compile option, add -D TEST_, modify the artifact type to Executable, supress extension so and prefix lib, suppress the -share option for the linker.
Now, just build Debug, Release, and Test as normal, what can be done independently. The Test target could be easily changed for say Test-Debug and Test-Release, to get a library self-test runned just after installation.

Changing default blue theme to green

I want to change the default blue color of my Sencha Touch application to green. The steps I followed are listed below:
gem update --system
gem install compass
compass create myfile
Copied a .scss file and pasted it in the touch-2.2.1/resources/sqss/ directory.
Pasted the following code in that file and named it happy.css:
$base-color: #709e3f;
#import 'sencha-touch/default/all';
#include sencha-panel;
#include sencha-buttons;
#include sencha-sheet;
#include sencha-tabs;
#include sencha-toolbar;
#include sencha-list;
#include sencha-layout;
#include sencha-loading-spinner;
compass compile happy.scss
Replaced the name happy.scss in the app.html page.
Ran the application, and I got the following error:
Syntax error: Undefined variable: "$font-family".\a on line 2 of
/Applications/XAMPP/xamppfiles/htdocs/touch-2.2.1/resources/themes/stylesheets/sencha-touch/default/src/_Class.scss\a
from line 1 of
/Applications/XAMPP/xamppfiles/htdocs/touch-2.2.1/resources/themes/stylesheets/sencha-touch/default/src/_all.scss\a
from line 1 of
/Applications/XAMPP/xamppfiles/htdocs/touch-2.2.1/resources/themes/stylesheets/sencha-touch/default/_all.scss\a
from line 3 of
/Applications/XAMPP/xamppfiles/htdocs/touch-2.2.1/resources/sass/happy.scss\a\a
1:
/Applications/XAMPP/xamppfiles/htdocs/touch-2.2.1/resources/sass/happy.scss
How can I solve this?
Add the following line
#import 'sencha-touch/default';
Before this line
#import 'sencha-touch/default/all';
Also as per documentation
There are a lot of changes from Sencha Touch 2.1 to 2.2,
The most important change to be aware of is the move away from using mixins
for each component
We found that using mixins for each component was quite slow when compiling your Sass,
so we decided to simply move to using #import to just include each component.
In Touch 2.1, your stylesheet looked like this:
#import 'sencha-touch/default/all';
#include sencha-panel;
#include sencha-buttons;
// and other components…
In Touch 2.2, it looks like this:
#import 'sencha-touch/default';
#import 'sencha-touch/default/Panel';
#import 'sencha-touch/default/Button';
// and other components

Creating DLL from CUDA using nvcc

I want to create a .dll from a CUDA code (kernel.cu) in order to use this library from an external C program. After some attempts I just left a simple C function in .cu file. Code follows:
kernel.cu
#include <stdio.h>
#include "kernel.h"
void hello(const char *s) {
printf("Hello %s\n", s);
}/*
kernel.h
#ifndef KERNEL_H
#define KERNEL_H
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#ifdef __cplusplus
extern "C" {
#endif
void __declspec(dllexport) hello(const char *s);
#ifdef __cplusplus
}
#endif
#endif // KERNEL_H
I tried to first generate a kernel.o object with nvcc and after i used g++ for creating DLL as following:
nvcc -c kernel.cu -o kernel.o
g++ -shared -o kernel.dll kernel.o -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\lib\x64" -lcudart
It works fine and generates kernel.dll. To test DLL file I wrote this simple program main.c:
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
void __declspec ( dllimport ) hello(const char *s);
#ifdef __cplusplus
}
#endif
int main(void) {
hello("World");
return 0;
}
compiled with:
g++ -o app.exe main.c -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -L. -lkernel
Result is a memory access error when execution starts.
Nevertheless, if I rename .cu file in .c (as it is just C code), using the same commands, it does work. nvcc's output changes, as far as I know because it uses default C compiler instead of CUDA one.
What do you think, is it a problem related with nvcc? Or am I making any mistake?
EDIT: I forgot some info which may be important. Warnings appear in the first call to g++ (when dll is created) and they are different depending on whether .cu .c or .cpp.
.cu
Warning: .drectve `/FAILIFMISMATCH:"_MSC_VER=1600" /FAILIFMISMATCH:"_ITERATOR_DEBUG_LEVEL=0"
/DEFAULTLIB:"libcpmt" /DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" /EXPORT:hello ' unrecognized
and it doesn't work.
.cpp and .c
Warning: .drectve `/DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" /EXPORT:hello ' unrecognized
and it works.
Solved. I still don't know why happened (maybe it is because of not using official compiler like Robert Crovella said), but replacing the two commands for making a DLL by this one works:
nvcc -o kernel.dll --shared kernel.cu
Note the double dash (nvcc works this way), and the fact of making it directly instead of creating first .o and then making DLL from the object.
In visual studio you can also make it compile into a .dll instead of a .obj file by navigating through the options:
DEBUG -> -Project name- Properties -> Configuration properties -> Configuration Type
Change the option from Application(.exe) to Dynamic Library(.dll)
You can find the dll after compiling in the DEBUG folder or RELEASE folder

Why am I unable to #ifdef stdafx.h?

I am trying to include 2 platform-specific stdafx.h files in my .cpp file, but the compiler is unhappy when I try to #ifdef it.
#ifdef _WIN32
#include "stdafx.h"
#elif _MAC
#include "MAC/stdafx.h"
#endif
You may wonder why I am using stdafx.h in the Mac code, but that is not important at the moment :).
When I try to compile the code on Windows, I receive: Fatal Error C1018. I tried enclosing other header files with #ifdef in the same file, and the compiler was happy. Therefore, it looks like Windows doesn't like stdafx.h to be #ifdef-ed, or that Windows only allows #include stdafx.h
to be the first line in the file.
So my question is, why?
Kat
When the compiler includes a pre-compiled header, it basically "forgets" anything that came before the header. Thus your #elif isn't matched to a #if anymore.
This is because you have Precompiled Headers turned on - turn it off and you should be fine.