Linux RT-Unable to link .lib to VSCode-Undefined reference to `DAQmxCreateTask' - c

I was trying to cross compile a C code with CMake inside Linux RT using VSCode. But I am encountering an error due to the mistake in linking (.so) file with project. I have gone through many solutions but failed to run the task. My code is given below:
#include<stdio.h>
#include"/home/admin/helloworld/src/NIDAQmx.h"
TaskHandle taskHandle=0;
int ret=0;
void main()
{
printf("Hello world");
ret=DAQmxCreateTask("task",&taskHandle);
printf("Return for creating task is %d\n",ret);
DAQmxStopTask (taskHandle);
DAQmxClearTask(taskHandle);
printf("Task closed ");
}
Error while running the task.
[ 50%] Linking C executable bin/helloWorld
CMakeFiles/helloWorld.dir/home/admin/helloworld/src/helloWorld.c.o:
In function `main':/home/admin/helloworld/src/helloWorld.c:11: undefined reference to `DAQmxCreateTask'
/home/admin/helloworld/src/helloWorld.c:13: undefined reference to `DAQmxStopTask'
/home/admin/helloworld/src/helloWorld.c:14: undefined reference to `DAQmxClearTask'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/helloWorld.dir/build.make:95: bin/helloWorld] Error 1
make[1]: *** [CMakeFiles/Makefile2:68:CMakeFiles/helloWorld.dir/all] Error 2
* The terminal process
"/bin/bash '-c', 'make'" failed to launch
(exit code: 2).
* Terminal will be reused by tasks, press any key to close it.
I modified my CMakeLists.txt as follows:
cmake_minimum_required(VERSION 3.7.2)
# project settings
project(helloWorld VERSION 0.1.0)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
set(CMAKE_GENERATOR "Unix Makefiles")
# executable settings
add_executable(helloWorld ../src/helloWorld.c)
set(CMAKE_BUILD_TYPE Debug)
LINK_LIBRARIES(NIDAQmx ../src/libnidaqmx.so)
If I remove the elements associated with NIDAQmx code working properly.

Related

Why does a function declared and included using header file show as undefined?

I have the following code in my files and all of these are in the same directory:
readMake.c:
#include <stdio.h>
#include "my_make.h"
int main(int argc, char* argv[]) {
printSomething();
}
printer.c:
#include <stdio.h>
int printSomething(){
printf("printed\n");
return 1;
}
my_make.h:
int printSomething();
However, when I try to compile and run my code, I get the following error:
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/prob1.dir/readMake.c.o: in function `main':
/cygdrive/c/Users/harsh/OneDrive/Documents/CSC352/assg9/prob1/readMake.c:5: undefined reference to `printSomething'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/prob1.dir/build.make:93: prob1.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/prob1.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/prob1.dir/rule] Error 2
make: *** [Makefile:124: prob1] Error 2
My IDE shows the proper signature of the printSignature function and where it is declared in the header file when I hover over the call in main, but the compilation doesn't seem to be working. Why is this happening and how can I resolve this?
I figured out a solution specific to CLion, unloading the CMakeLists.txt file and then creating a new one seems to resolve the issue.
I had to do 'Tools>CMake>Unload'
and then create a new CMakeLists.txt file which was automatically done by clicking an option appearing at the top of the window and selecting all of the files from a list of checkboxes.

Unable to compile under the eclipse/code composer studio

Im trying to compile the next code
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <sysctl.h>
#include <sysctl.c>
#include <inc/hw_ints.h>
#include <tm4c1294ncpdt.h>
uint32_t i,CTA;
void main(void){
SYSCTL_RCGCGPIO_R=0X1008;
i=SYSCTL_RCGCGPIO_R;
GPIO_PORTD_AHB_DIR_R=0X01;
GPIO_PORTD_AHB_DEN_R=0X03;
NVIC_EN0_R=0X08;
GPIO_PORTD_AHB_IM_R |=0X02;
GPIO_PORTD_AHB_IS_R =0X00;
GPIO_PORTD_AHB_IEV_R |=0X02;
GPIO_PORTD_AHB_ICR_R |=0X02;
GPIO_PORTN_DIR_R =0X03;
GPIO_PORTN_DEN_R =0X03;
GPIO_PORTD_AHB_DATA_R =0X00;
while (1)
{
CTA=0;
GPIO_PORTN_DATA_R ^=0X01;
SysCtlDelay(2666666);
GPIO_PORTD_AHB_DATA_R |=0X01;
SysCtlDelay(100);
GPIO_PORTD_AHB_DATA_R &=~0X01;
}
}
int ECHO_ISR(void){
while (((GPIO_PORTD_AHB_DATA_R & 0X02)== 0X02)& (CTA<0XFFF))
{
CTA++;
}
GPIO_PORTD_AHB_ICR_R |=0X02;
return 0;
}
It is a little sonar using the HC-SR04 module the code composer shows the next output
Compilation failure
subdir_rules.mk:7: recipe for target 'main.obj' failed
Command-line error #1965: cannot open source file "/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/include/"
1 catastrophic error detected in the compilation of "../main.c".
Compilation terminated.
gmake: *** [main.obj] Error 1
Command-line error #1965: cannot open source file "/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/include/"
1 catastrophic error detected in the compilation of "../tm4c1294ncpdt_startup_ccs.c".
Compilation terminated.
gmake: *** [tm4c1294ncpdt_startup_ccs.obj] Error 1
Building file: "../tm4c1294ncpdt_startup_ccs.c"
Invoking: ARM Compiler
"/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --include_path="/home/user/workspace_v8/5" --include_path="/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/include" --include_path="/home/user/ti/tivaware_c_series_2_1_4_178/inc" --include_path="/home/user/ti/tivaware_c_series_2_1_4_178" --include_path="/home/user/ti/tivaware_c_series_2_1_4_178/driverlib" --include_path="/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/bin" --include_path="/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/lib" --include_path="/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/include" --preinclude="/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/include/" --define=ccs="ccs" --define=PART_TM4C1294NCPDT -g --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --preproc_with_compile --preproc_dependency="tm4c1294ncpdt_startup_ccs.d_raw" "../tm4c1294ncpdt_startup_ccs.c"
>> Compilation failure
subdir_rules.mk:7: recipe for target 'tm4c1294ncpdt_startup_ccs.obj' failed
gmake: Target 'all' not remade because of errors.
**** Build Finished ****
It shows a Error 1, but no more details. The includes are the /inc and /driverlib besides the system added alone.
It says it cant open the /home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/include/ but Its already added to the project
Update
After removing the preinclude it now throws more errors
Remove "/home/user/ti/ccs831/ccsv8/tools/compiler/ti-cgt-arm_18.1.6.LTS/include/" from the preinclude section

Undefined symbols for architecture x86_64 and linker command failed with exit code 1

I run the following code from APUE
#include "apue.h"
#include <sys/wait.h>
void pr_exit(int status)
{
if (WIFEXITED(status))
printf("normal termination, exit status = %d\n",
WEXITSTATUS(status));
else if (WIFSIGNALED(status))
printf("abnormal termination, signal number = %d%s\n",
WTERMSIG(status),
#ifdef WCOREDUMP
WCOREDUMP(status) ? " (core file generated)" : "");
#else
"");
#endif
else if (WIFSTOPPED(status))
printf("child stopped, signal number = %d\n",
WSTOPSIG(status));
}
but get error:
$ cc my_wait.c
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I checked multiple times and ensure there no difference with the book's instruction ..
How could I solve the problem?
Transferring a comment into an answer, as requested.
The error message says "there is no function main()", and the source code you show has no function main(), so there's minimal surprise that there's that error message.
Where did you think main() was going to come from?
When you build a program, there needs to be a main() from somewhere, and the standard C library does not provide an implementation. (If you work with Flex or Lex, or Bison or Yacc, you may find minimal main() programs in their libraries, but these are an exception, not the rule.)

Unable to compile a C file in Contiki

I am trying to write a code in contiki that allows motes to randomly generate values.
Below is the code I tried:
#include "contiki.h"
#include "stdio.h" /* For printf() */
#include "stdlib.h"
PROCESS(random_process, "Random process");
AUTOSTART_PROCESSES(&random_process);
PROCESS_THREAD(random_process, ev, data)
{
PROCESS_BEGIN();
int r=rand();
printf("Hello, world. Random Number is %d",r);
PROCESS_END();
}
While generating the makefile I get the below error:
user#instant-contiki:~/Desktop/Random$ make target=native random_sample
TARGET not defined, using target 'native'
CC random_sample.c
LD random_sample.native
contiki-native.a(broadcast-annou): In function `set_timers':
/home/user/contiki-2.7/core/net/rime/broadcast-announcement.c:171: undefined reference to `random_rand'
collect2: ld returned 1 exit status
make: *** [random_sample.native] Error 1
rm random_sample.co
Can someone please help me with this? Thanks in advance.
You have not configured your project properly, you have to setup Makefile and project-conf.h to start with contiki, read the following hello-world example: http://github.com/contiki-os/contiki/tree/master/examples/hello-world.
I recommend you use the example in the link as a project start files.

Error on compiling c file on MPLAB X ide

I get following errors when trying compile using MPLAB X on Windows..
newmain.c:40:9: error: unknown configuration setting: 'JTAGEN'
newmain.c:61:2: error: 'LATA' undeclared (first use in this function)
newmain.c:62:2: error: 'TRISA' undeclared (first use in this function)
newmain.c:61:2: error: 'LATA' undeclared (first use in this function)
I tried this on 2 different machines (on Windows 8.1 and Vista), but they all gave me same error.
It seemed like that xc.h file is already included to project since I can open that file. And also I googled for this problem but there wasn't a solution for this.
Thank you very much if you can give me a possible way to solve this.
I also attached photo describing project properties ​for this project.
Following is full description of error :
- CLEAN SUCCESSFUL (total time: 52ms) make -f
nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]:
Entering directory 'Z:/Personal Data/MPLABXProjects/Lab01.X' make -f
nbproject/Makefile-default.mk
dist/default/production/Lab01.X.production.hex make[2]: Entering
directory 'Z:/Personal Data/MPLABXProjects/Lab01.X' "Z:\Program Files
(x86)\Microchip\xc32\v1.40\bin\xc32-gcc.exe" -g -x c -c
-mprocessor=32MX340F512H -MMD -MF build/default/production/newmain.o.d -o
build/default/production/newmain.o newmain.c newmain.c:40:9: error:
unknown configuration setting: 'JTAGEN' #pragma config JTAGEN = OFF
// JTAG Enable OFF (only use for '250)
nbproject/Makefile-default.mk:105: recipe for target
'build/default/production/newmain.o' failed ^ newmain.c: In function
'main': make[2]: Leaving directory 'Z:/Personal
Data/MPLABXProjects/Lab01.X' newmain.c:61:2: error: 'LATA' undeclared
(first use in this function) nbproject/Makefile-default.mk:78: recipe
for target '.build-conf' failed LATA = 0; // Set value of PORT A
output to 0. ^ make[1]: Leaving directory 'Z:/Personal
Data/MPLABXProjects/Lab01.X' nbproject/Makefile-impl.mk:39: recipe
for target '.build-impl' failed newmain.c:61:2: note: each undeclared
identifier is reported only once for each function it appears in
newmain.c:62:2: error: 'TRISA' undeclared (first use in this
function) TRISA = 0; // Set all pins on PORT A to output ^ make[2]:
*** [build/default/production/newmain.o] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 BUILD FAILED
(exit value 2, total time: 203ms)
And source is
#include <xc.h>
#pragma config FWDTEN = OFF, JTAGEN = OFF
void delay(void);
unsigned int ctr = 0;
unsigned int delayVal = 2048;
int main(void)
{
LATA = 0;
TRISA = 0xFF00;
while(1)
{
LATA = 0x0055;
delay();
LATA = 0x00AA;
delay();
ctr++;
}
}
void delay(void)
{
unsigned int i,j;
for (i = 0; i < delayVal; i++)
{
for (j = 0; j < 20; j++);
}
}
The errors you receive indicate that the compiler does not see any libraries to reference those registers to. It treats them as regular variables instead.
You should include the specific header file for the processor you are using and also check to see what registers are structured in there to make more sense of your problem.

Resources