1 1
serkam

ARMBIAN's GCC for OPi Zero doesn't compile threads

Recommended Posts

Hi

 

I am trying to compile a program test for my new OPi Zero that is running ARMBIAN.

 

From a Hello World program test, I am trying to create a thread that will blink the led at PA17 gpio pin, but GCC's linker complains saying that can't locate pthread_create() function. I am using pthread.h.

 

Somebody found similar issue?

 

Sergio

 

Share this post


Link to post
Share on other sites

Hi jernej

 

The problem is that I am using Visual Studio with Linux Extension Plugin to remotely compile my program and, despite the program is compiled inside OPi Zero environment, I don't know where in VS I can modify the compiling parameters to adjust -lpthread option.

 

I am searching for how to place -lpthread option yet.

 

Sergio

Share this post


Link to post
Share on other sites

Hi jernej and martinayotte.

 

Yessss, apparently worked.

 

I put in Visual Studio's Project/Configuration Properties/Linker/Additional Options/-lpthread and immediately the compilation was done.

 

I don't know if all the rest is OK. 

 

I will post the results soon.

 

Thank you all.

 

Sergio

Share this post


Link to post
Share on other sites

Working perfectly:

 

#include <unistd.h>
#include <pthread.h>
#include <cstdio>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "string.h"
#include "gpio_lib.h"

void *thread_BLINKY(void *arg);



int main()
{
	char status = 1;
	char dado[80];
	int ret = 0;
	pthread_t s_thread_BLINKY;

	printf("hello from ConsoleApplication1! %s %s\n", __DATE__, __TIME__);

	ret = pthread_create(&s_thread_BLINKY, NULL, thread_BLINKY, (void *)NULL);
	if (ret < 0)
	{
		printf("WARPTEC: nao conseguiu criar thread BLINKY\n");
	}


	while (status)
	{
		printf("comando = ");
		scanf("%s", dado);

		if (!strcmp("fim", dado)) status = 0;
	}

    return 0;
}

void *thread_BLINKY(void *arg)
{

	sunxi_gpio_init();
	sunxi_gpio_set_cfgpin(SUNXI_GPA(17), SUNXI_GPIO_OUTPUT);

	while (1)
	{
		sunxi_gpio_output(SUNXI_GPA(17), 1);
		usleep(200000);
		sunxi_gpio_output(SUNXI_GPA(17), 0);
		usleep(100000);
		sunxi_gpio_output(SUNXI_GPA(17), 1);
		usleep(200000);
		sunxi_gpio_output(SUNXI_GPA(17), 0);
		usleep(500000);
	}

}

Thank you.

 

Sergio

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
1 1