# undefined reference to "omp"



## Tu22M3 (Dec 8, 2009)

Hello,
I amend my TCP/IP source code,
in /usr/src/sys/netinet/tcp_output.c
add 
	
	



```
#include<sys/omp.h>
```
 and add below code in function of 
int tcp_output(struct tcpcb *tp)d


```
int tid;
omp_set_num_threads(4);
#pragma omp parallel
{
   tid=omp_get_thread_num();
   printf("%d\n",tid)
}
```

of course,I add -fopenmp in /usr/src/sys/conf/kern.pre.mk
but get the error as below:


```
linking kernel.debug
tcp_output.o(.text+0x477):In function 'tcp_output':
/usr/src/sys/netinet/tcp_output.c:162:undefined reference to 'omp_set_num_threads'
tcp_output.o(.text+0x4a2):/usr/src/sys/netinet/tcp_output.c:148:undefined reference to 'GOMP_parallel_start'
tcp_output.o(.text+0x4a2):/usr/src/sys/netinet/tcp_output.c:148:undefined reference to 'GOMP_parallel_end'
/usr/src/sys/netinet/tcp_output.c:165:undefined reference to 'omp_get_num_threads'
```

What's wrong to my kernel?

Thank you for replies.

Cheers,

-- Wang


----------



## SirDice (Dec 8, 2009)

I'm no kernel hacker but I'm quite sure you can't just go around linking external libraries to it and expect it to work.


----------



## Tu22M3 (Dec 9, 2009)

SirDice said:
			
		

> I'm no kernel hacker but I'm quite sure you can't just go around linking external libraries to it and expect it to work.



If not add -fopenmp in the linking,it can't  identify #pragma omp parallel
so,whether or not it run short of some compilations?


----------



## SirDice (Dec 9, 2009)

Tu22M3 said:
			
		

> If not add -fopenmp in the linking,it can't  identify #pragma omp parallel


Yes, which also means you can't use it. Kernel programming is an entirely different beast compared to userland programming.


----------



## Tu22M3 (Dec 9, 2009)

Thanksï¼
But how can I correct it?I have no ideal of it.


----------



## SirDice (Dec 9, 2009)

Remove the code you added. What exactly are you trying to accomplish?


----------



## Tu22M3 (Dec 10, 2009)

I want to add parallel OpenMP  for TCP/IP code.Initially, I think if add the support of lib,it may be succesful.


----------



## SirDice (Dec 10, 2009)

Why? AFAIK it's already multithreaded.

Have a look here:
http://www.freebsd.org/projects/netperf/index.html


----------



## Tu22M3 (Dec 10, 2009)

Thanks!
I just want to kown how to use OpenMP in TCP/IP code. Although  it have enhance the performance of the FreeBSD network stack,there may be another way to  improve network stack. And OpenMP is much more simply.
    Now, I have found these files and directory have important effect to compiler.

```
/usr/src/sys/conf/kern.pre.mk,
/usr/src/sys/conf/kern.post.mk,
/usr/src/sys/conf/kern.mk,
/usr/src/sys/conf/kmod.mk,
/usr/src/contrib/gcclibs/libgomp/
```

   The compiler can't build tcp_output.o


----------



## Jungle (Mar 9, 2012)

Please tell me how *yo*u executed omp parallel. *M*orever how to link to use omp in the program?


----------



## Jungle (Mar 9, 2012)

*It's* throwing errors like undefi*ne*d reference to omp_set_num_threads in MINGW gcc 4.6.2 version. *W*hen *I* am trying the execution with gcc -fopenmp title.c. *It's* giving undefi*ne*d reference to printf, scanf and many things indir*e*clty stdio.h not in a w*o*rking c*o*ndition. Please help me. Wh*a*t *I* sh*oul*d do*?* *I* changed the PATH variable for windows to C:\MinGW\lib\gcc\4.6.2\.


----------



## SirDice (Mar 9, 2012)

Jungle said:
			
		

> What I should do? I changed the PATH variable for windows to C:\MinGW\lib\gcc\4.6.2\


Windows? You do realize you are on a FreeBSD forum?


----------



## DutchDaemon (Mar 9, 2012)

Moreover, this topic is over two years old. On top of that: stop writing like you are text messaging.


----------

