Include files in wrong directory

Hey!

Just installed openSUSE 11.3. This is my first time on openSUSE.

I wanted to try this distro for running an EtherCat master from EtherLab.

Before installing the master, i had to compile my kernel and install the kernel sources.

My problem occurred when compiling the kernel modules for the master.

# make modules
make -C "/usr/src/linux/" M="/home/john/ethercat-default" modules
make[1]: Entering directory `/usr/src/linux-2.6.34-12'
  CC [M]  /home/john/ethercat-default/examples/mini/mini.o
/home/john/ethercat-default/examples/mini/mini.c:31:27: fatal error: linux/modules.h: No such file or directory
compilation terminated.
make[4]: *** [/home/john/ethercat-default/examples/mini/mini.o] Error 1
make[3]: *** [/home/john/ethercat-default/examples/mini] Error 2
make[2]: *** [/home/john/ethercat-default/examples] Error 2
make[1]: *** [_module_/home/john/ethercat-default] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.34-12'
make: *** [modules] Error 2

I had a look around and found the missing header files in /usr/src/linux/include/linux/

Being a novice, I have no idea how to make the compiler look in the correct directories. Tried adding the absolute path in the mini.c file, but it failed as that header included another file… and so on.

Any help is appreciated.

//John

If the kernel that you compiled is the source from official OpenSUSE repo, you could install and its headers(if I’m not mistaken kernel-devel was the package for environment needed to build kernel modules). The standard includes are in /usr/include/ if you want to handle this manually.


hundred-and-one symptoms of being an internet addict:
You refer to your age as 3.x.

Thanks for your quick reply!

I tried linking the file

ln -s usr/src/linux/include/linux/module.h /usr/include/linux/module.h

But i still get the message from make that module.h doesnt exist

Hi
Probably worth are read
of /usr/share/doc/packages/kernel-source/README.SUSE

I use the KMP option and build kernel module rpms, for me it’s much
quicker…


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.3 (x86_64) Kernel 2.6.34-12-default
up 4 days 18:16, 3 users, load average: 0.12, 0.07, 0.02
GPU GeForce 8600 GTS Silent - Driver Version: 256.44

Sorry for the confusion… /usr/include/ seems to not be what you need. Just check my system and modules.h is found only in /lib/modules/uname -r/build/include/config/…alto it’s just empty file, moreover - all files there seems to be just empty files :slight_smile: guess they are only for configuration purpose.
Seems like problem with the Makefile.

P.S. I never try what malcolmlewis sad, but sure it sound like pretty nice opportunity…


A law to reduce crime states: "It is mandatory for a motorist with criminal
intentions to stop at the city limits and telephone the chief of police as he
is entering the town.
[real standing law in Washington, United States of America]

i even tried copying the file. With the same result. I dont understand. Where does the compiler look?
i compile the ethercat master using

#./configure --with-linux-dir=/usr/src/linux/ --enable-8139too=no --enable-generic
#make
#make modules
module.h not found

Also tried this process from the “uncompiled” kernel with the same result

Any ideas?

ok… i tried malcomlewis idea.

#zypper install kernel-syms
#make -C /usr/src/linux-obj/i586/default M=$(pwd)

…still the same output.

Hi
Do you have a download link to the module source??

I cloned it from the repo using this command

hg clone http://etherlabmaster.hg.sourceforge.net:8000/hgroot/etherlabmaster/etherlabmaster ethercat-default

Hi
Just looking at in now :wink:

here is the manual if that helps: http://www.etherlab.org/download/ethercat/ethercat-1.5-6129a5f715fb.pdf
Installation notes is at the end…

Hi
Just an update, I have it building now, 2.6.34 uses slab.h for kfree/kmalloc so have added patches to the relevant files. I’m only using the generic (as per your configure) as it doesn’t contain updated modules in the devices section for 2.6.34. The latest they have is 2.6.31.

Cool!
I have no idea how to patch source files.
Looking forward to see your result.

Really, thanks for helping man

OK in the interests of getting it to you to try out, I have disabled a check it was failing on, if this test version works, then can sort out the error.

I’ve built on the openSUSE Build Service and it should be here;
software.opensuse.org: Search Results
or
Index of /repositories/home:/malcolmlewis:/Testing/openSUSE_11.3

You can see all the files to build the application here (see the ethercat.spec for how it’s built);
https://build.opensuse.org/package/files?package=ethercat&project=home%3Amalcolmlewis%3ATesting

All right the C junkies lurking… Here is the errors I’m getting. It’s the last ones prefixed with the E (master.c) that causing the real issue, but not sure if it’s a result of the other warnings?


I: Program is using implicit definitions of functions getting
   pointers or implemented by macros. These functions need to use their
   correct prototypes to allow correct argument passing on e.g. x86_64 .
     - Implicit memory/string functions need #include <string.h>.
     - Implicit *printf functions need #include <stdio.h>.
     - Implicit *printf functions need #include <stdio.h>.
     - Implicit *read* functions need #include <unistd.h>.
     - Implicit *recv* functions need #include <sys/socket.h>.
W: ethercat implicit-pointer-decl common.c:58
W: ethercat implicit-pointer-decl sdo_request.c:58

I: Program is likely to break with new gcc. Try -fno-strict-aliasing.
W: ethercat strict-aliasing-punning DataTypeHandler.cpp:182, 201, 342, 359
W: ethercat strict-aliasing-punning slave_config.c:347, 358

I: Program returns random data in a function
E: ethercat no-return-in-nonvoid-function master.c:52

I: Program returns random data in a function
E: ethercat no-return-in-nonvoid-function master.c:52

At line 52-54 It’s;


#ifdef EC_EOE
#include "ethernet.h"
#endif

Is the issue in ethernet.h?

Well that always happens…post and then find the problem. There were two files called master.c I was looking at the wrong one.

@john_erlandsson I’ve uploaded the fixes so the newer one should be good to go for you. Shouldn’t take too long for it to appear.

Ok… So i installed the RPMs, hooked up my node and it simply worked…
Or at least it seemes to work, the lights start flashing and the ethercat command finds the node. I can now start experementing with the programming.

You have been more than helpful.

I still have a lot of questions.

Did you build the RPM’s with the generic ethernet driver or with all of them?

Why is it a good idea to build KMP’s instead of compiling the source?

You said that you patched the files to make it look for the kernel functions in a different include file. How did you do that?

How do you find the patience to help newbies such as myself to perform complicated tasks like this?

Again. Thank you!

//John

Hi
I built it with the following options;


%configure --enable-tty \
--enable-generic \
--enable-8139too=no \
--enable-static=no \
--with-linux-dir=/usr/src/linux-obj/%_target_cpu/default

Full spec file is here;
https://build.opensuse.org/package/view_file?file=ethercat.spec&package=ethercat&project=home%3Amalcolmlewis%3ATesting&srcmd5=cb7141442b1f1e1d8b9e5aa87c78e46f

Well a K(ernel)M(odule)P(ackage) is just an rpm for the module. It just
builds easier and integrates with the system better (what more can i
say…) it’s based around the document here:
ftp://sdk.provo.novell.com/ndk/kmpm/Kmpm-code11.pdf

For patching I use the command;


diff -Naur <filename> <filename.orig>

It’s just a matter of then copying the original file to filename.orig
and making the changes then running the above command from the source
root directory. For example;


--- examples/mini/mini.c    2010-08-25 16:34:15.000000000 -0500
+++ examples/mini/mini.c.orig   2010-08-25 18:03:24.000000000 -0500
@@ -33,6 +33,15 @@
#include <linux/interrupt.h>
#include <linux/err.h>

+/* 25.08.10   (Malcolm J Lewis)
+ *            Allow to compile with 2.6.34
+ *            Added slab.h include >= 2,6,34
+ *            using kmalloc/kfree requires including slab.h
+ */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)
+#include <linux/slab.h>
+#endif
+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
#include <linux/semaphore.h>
#else

The first two lines are the filenames and full path, then next line
is where the patch starts, then lines I’ve added are indicated with a +.

I normally then just pipe them into a file with >> to create an overall
patch as can be seen here;
https://build.opensuse.org/package/view_file?file=ethercat.patches&package=ethercat&project=home%3Amalcolmlewis%3ATesting&srcmd5=cb7141442b1f1e1d8b9e5aa87c78e46f

Well I guess sometimes it’s just easier to build as explaining can take
longer (as i think would have been in this case) to work through the
steps to get it building for you (less frustration so you can get on
with your experimenting).

Also using the build service enables the rpm to be build to better
conform with openSUSE standards and easier integration into your system.

The other bonus in the ether code, if you look there was a file called
ethercat.spec.in which you could have used to build a basic rpm had
there been no patching required. I used that as a basis for my build,
but split out as per the ‘openSUSE’ way of building rpms…

Oh, it may build one more time as I am down to the last funny;


I: Program is using implicit definitions of functions getting
pointers or implemented by macros. These functions need to use their
correct prototypes to allow correct argument passing on e.g. x86_64 .
- Implicit memory/string functions need #include <string.h>.
- Implicit *printf functions need #include <stdio.h>.
- Implicit *printf functions need #include <stdio.h>.
- Implicit *read* functions need #include <unistd.h>.
- Implicit *recv* functions need #include <sys/socket.h>.
W: ethercat implicit-pointer-decl sdo_request.c:58

I have got rid of all the others from my earlier post.

If you have more questions…please ask :slight_smile:

Once I have it built, I need to go back to the ethercat site and push
those changes to them… :wink:


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.3 (x86_64) Kernel 2.6.34-12-default
up 5 days 15:04, 4 users, load average: 0.07, 0.08, 0.02
GPU GeForce 8600 GTS Silent - Driver Version: 256.44

The RPMs work, but i want to be able to make my own. Say if i want to use the 8139too driver someday, or rtai.
So, i tried patching the mini.c file the same way that you did and then run** #make modules** again. But my compiler still tells me that linux/module.h does not exist.

I dont understand. I tried commenting out the #include </linux/module.h> line in my patch, but it seems that mini.c uses it for some other functions (Besides kmalloc and kfree).
Even after actually copying the module.h file from /usr/src/linux/include/linux/ to /usr/include/linux/ i still get the same result.

Why doesnt the compiler understand?

I think the maximum rpm guide could be helpful. Ill go through it after finishing paining my house…

Hi
I’ve fixed (well added the 8139too module for the 2.6.34 kernel), so it should be building soon so I preempted your issue… :slight_smile:

It’s because of the changes in the 2.6.34 kernel have you installed linux-glibc-devel (aka linux-kernel-headers)?

I’ve always had issues like your seeing, hence the move to KMP as these always seem to build fine.

I’ve pushed my changes upstream, so will also add the module now. Hopefully when the actual release on 1.5 becomes final these changes will be included.

Why don’t you start a new thread about the rtai one when the time comes?