serkam Posted January 26, 2017 Share Posted January 26, 2017 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 Link to comment Share on other sites More sharing options...
jernej Posted January 26, 2017 Share Posted January 26, 2017 Please provide full command. Did you forget -lpthread ? Link to comment Share on other sites More sharing options...
martinayotte Posted January 26, 2017 Share Posted January 26, 2017 You probably only need to add "-lpthread" to the linker. Link to comment Share on other sites More sharing options...
serkam Posted January 26, 2017 Author Share Posted January 26, 2017 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 Link to comment Share on other sites More sharing options...
jernej Posted January 26, 2017 Share Posted January 26, 2017 Ah, ok, then I can't really help you because I'm not familiar with Linux Extension Plugin. Link to comment Share on other sites More sharing options...
serkam Posted January 26, 2017 Author Share Posted January 26, 2017 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 Link to comment Share on other sites More sharing options...
serkam Posted January 26, 2017 Author Share Posted January 26, 2017 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 Link to comment Share on other sites More sharing options...
Recommended Posts