Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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

 

  • Author

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

  • Author

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

  • Author

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

 

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.