How to include linux/module.h in my source file? - c

I have looked at other similar questions around stackoverflow, but it doesn't seem to work for me. I am trying to compile a code sample, and it needs these header files:
linux/module.h
linux/modversion.h
linux/sched.h
linux/tqueue.h
But I keep getting errors saying that those files can't be found. I know I should add them to the kernel, but can you please guide me through the process and tell me how to get this done. Thanks in advance for any help.
The code sample can be found here.

You probably want to compile kernel source code first, or check if the below path exists
/lib/modules/kernel-version/build
Or more precisely
/lib/modules/`uname -r`/build
Or
path to your kernel build
This is generally the path where your kernel build tree is present.
Needless to say normal gcc based compilation wont work here.
This should get you started

Some of these files are shipped with any linux distro in :
/usr/include/linux/
but if you haven't linux installed in your machine see linux source tree in github repo :
https://github.com/torvalds/linux/tree/master/include/linux

Related

CCS unresolved symbols in linker or compiler causing errors

I am newbee c programmer so be patient. I have a MSP430 C project in Code Composer Studio 7.3 using windows 7. My project (USB) was working fine and then I tried to add more code to incorporate a SPI interface and everything went sideways. I restored my original code but now have problems that weren't there before. Seems to compile but has several unresolved symbols errors in the linker (I think). I have searched/researched many answers to these types of problems on the forum and tried many things (over the past two days!!) and cannot resolve my problem. Possibly I made things worse by copying library/functions directly into my project directory but still didn't seem to change anything. The errors are related to standard MSP430 functions, not my code. My project tree looks like:
project tree
Errors from Console are:
console errors
From everything I have read it indicates that either I have a compiler library path problem or a linker file path problem. Tried a lot of combinations to no avail. Following are the compiler and linker path info:
linker 1
linker 2
If I look in my repository of library stuff downloaded from TI you can see that the dma.h and dma.c files which reference the error message lines in the files are there and I don't understand why the linker can't do its thing.
dma file tree
In the linker under library files I noticed the original libmath.a file didn't point to anything so I found one and added it (not help). Also the libc.a points to a section of 3 directories (different versions of a tool) which each have a different version of libc.a and I think I tried all of them. See below for directories
directories
Any help would be greatly appreciated
A CLUE POSSIBLY: CLUE? In my quest to solve my issues, I created a new CCs project and pasted my main.c file in and then went through a series of compiles solving the errors as the showed up. I was down to one error : can't open source file hal.h. I believe this is a file that was included with the usb example code I started with. After copying it into my project I am back to square on with all the errors listed above. To get here I only needed to point the compiler to driverlib to solve previous errors. The hal.h file seems to only include driverlib.h which is also referenced in my main function so why all the errors??
FIXED BUT WHY!!!
To solve this issue I imported the drivlib directory from the TI repo on my D drive into my project. Now everything compiles. Can anyone tell me why I had to do that given that I had path directives to look on my D drive?? Can it be related to search path length being too long?

Missing .dll files when compiling with notepad++ and minGW

Recently I started coding in C and I tried to find a way to compile with notepad++. After thouroughly installing minGW with some basic upgrades I tried to use a specific code that allows me to compile.
This code is can be found on thise webpage:
http://www.thecrazyprogrammer.com/2015/08/configure-notepad-to-run-c-cpp-and-java-programs.html
So you can see what I am trying to do.
However when I try to execute the command, it gives me the warning that several .dll files are missing.
These are the ones: libgmp-10.dll ; libiconv-2.dll ; libmpc-3.dll and libmpfr-4.dll
After some research, I added those files to the bin, lib and libexec folders of the minGW headfolder and it resulted in giving me another missing lib file:
libgcc_s_dw2-1.dll
Ok I added that one too and now it starts over saying it is missing libiconv-2.dll
I added all the folders to my PATH and there is nothing else I can think of that is wrong =(
If u find a solution, please explain it in detail since I am not a programmer and only have little experience with going this 'deep' into files and paths etc ...
Thanks in advance!
Oh I found it myself I think.
I read somewhere that using gcc in stead of g++ could help and after copying the missing files to a bunch of folders it worked :D

How to compile LuaFileSystem library and get .dll file WITHOUT luarocks?

So, I got file "lfs.c" "lfs.h" "lfs.def" and ".gitignore". I tried installing MinGW and typing in that command: gcc lfs.c (Keep in mind that I'm a total newbie in such things), which leaves me with error "failed to include lua.h"... I don't know how to do that, can anyone please explain to me how to do that? Or at least give me the link to already compiled lfs.dll?
You are likely to be missing Lua include files; see this SO answer for details on how to set it up.
Simply getting lfs.dll may not be so easy as different DLLs may depends on different Lua DLLs on Windows. I have lfs.dll that is compiled against Lua51.dll, so if this works for your project/needs, you can get a compiled version here.

How would one compile a program for the Coldfire toolchain?

I'm trying to compile a simple hello world application to be run on uCLinux (2.4) which is running on a board with a Freescale Coldfire (MCF5280C) processor...and I'm not quite sure what to do here.
I know I need to compile with the correct version/tools from Freescale to target this hardware, so I downloaded and installed the Coldfire tool chain and verified that one I have is for my target:
mike#linux-4puc:/usr/local/m68k-elf/bin> ./gcc -v
Reading specs from /usr/local/lib/gcc-lib/m68k-elf/2.95.3/specs
gcc version 2.95.3 20010315 (release)(ColdFire patches - 20010318 from http://fiddes.net/coldfire/)(uClinux XIP and shared lib patches from http://www.snapgear.com/)
I tried a simple gcc "file" type command:
mike#linux-4puc:/home/mike> /usr/local/m68k-elf/bin/gcc test.c
/usr/local/m68k-elf/bin/ld.real: cannot open crt0.o: No such file or directory
collect2: ld returned 1 exit status
Which does not work at all.. so it's clearly more complex that than. The output almost looks like it wants me to build the tool chain before I use it?? Anyone ever done this before? Not sure what I need to do or if I just need some flags.
You might also try seeing if you have a command called m68k-elf-gcc or something along those lines. This is a common naming for cross-compilers.
As for your problem, it sounds like there is something wrong with your compiler setup. crt0.o is the object file that contains C-runtime setup code. The linker (what is actually giving the error) should know where this file is if setup properly.
When you installed you should have run make install as the last step without having modified anything since the make step. The configuration step will setup certain variables and such based on the path where it's supposed to be installed.
Where did you get a FreeScale toolchain? I took a look at their site and it seemed only third parties supplied C++ cross-compilers. In the toolchain I get from NetBurner (for use with their hardware) the crt0.o file exists under the gcc-m68k\m68k-elf\lib directory.

Error during the executing a file with GMP library

I have installed gmp library many times and run several programs. Every time I run my first program after 'successful' compilation, i hit the following error.
./a.out: error while loading shared libraries:
libgmp.so.10: cannot open shared object file: No such file or directory
After immense amount of looking over the net, I was not able to resolve this issue correctly.
PS: One suggestion in one of the forums was to create the link to the library file in i think /usr/lib. But it was condemned badly in the same thread.
Eventually I want my code to run. A quick solution for this issue would be appreciated.
Thanks!!
Try ldd ./a.out which should show you where the system is looking for the lib. But yeah, it means that it's not correctly installed, or that the search path for this lib is not good.
So the symlink may be a good idea. How did you installed GMP on your computer? apt-like or compilation?

Resources