I'm not much of a C/C++ programmer myself, but I've been tasked with building a Deconvolution program used in my lab.
Here is the complaint I've been getting:
[ 10%] Building (Device) NVCC /home/chris/Desktop/Clarity-1.0/src/WienerDeconvolveGPU.cu: /home/chris/Desktop/Clarbuild/src/cuda/src/WienerDeconvolveGPU.cu_Clarity_generated.cpp
[ 13%] Building CXX object CMakeFiles/Clarity.dir/src/WienerDeconvolve.o
/home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx: In function ‘ClarityResult_t Clarity_WienerDeconvolve(float*, Clarity_Dim3, float*, Clarity_Dim3, float*, float)’:
/home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx:211: error: ‘malloc’ was not declared in this scope
/home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx:246: error: ‘free’ was not declared in this scope
make[2]: *** [CMakeFiles/Clarity.dir/src/WienerDeconvolve.o] Error 1
make[1]: *** [CMakeFiles/Clarity.dir/all] Error 2
make: *** [all] Error 2
The normal solution I've found is to insert #include cstlib in the code, WienerDeconvolve.cxx, but when I do that, this happens:
[ 2%] Building CXX object CMakeFiles/Clarity.dir/src/WienerDeconvolve.o
Linking CXX static library libClarity.a
[ 89%] Built target Clarity
Linking CXX executable ConvolutionTest
[ 92%] Built target ConvolutionTest
Linking CXX executable JansenVanCittertTest
[ 94%] Built target JansenVanCittertTest
Linking CXX executable MaximumLikelihoodTest
[ 97%] Built target MaximumLikelihoodTest
Linking CXX executable WienerFilterTest
../../libClarity.a(WienerDeconvolve.o): In function `ComplexConjugate(float2)':
WienerDeconvolve.cxx:(.text+0x2a0): multiple definition of `ComplexConjugate(float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x0): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexAdd(float2, float2)':
WienerDeconvolve.cxx:(.text+0x2c6): multiple definition of `ComplexAdd(float2, float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x24): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexMultiply(float2, float2)':
WienerDeconvolve.cxx:(.text+0x300): multiple definition of `ComplexMultiply(float2, float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x54): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexScale(float2, float)':
WienerDeconvolve.cxx:(.text+0x34e): multiple definition of `ComplexScale(float2, float)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x84): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexMultiplyAndScale(float2, float2, float)':
WienerDeconvolve.cxx:(.text+0x378): multiple definition of `ComplexMultiplyAndScale(float2, float2, float)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xa8): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexMagnitudeSquared(float2)':
WienerDeconvolve.cxx:(.text+0x3ed): multiple definition of `ComplexMagnitudeSquared(float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xd8): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexConjugate(float2)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x0): multiple definition of `ComplexConjugate(float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x0): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexAdd(float2, float2)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x24): multiple definition of `ComplexAdd(float2, float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x24): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMultiply(float2, float2)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x54): multiple definition of `ComplexMultiply(float2, float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x54): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexScale(float2, float)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x84): multiple definition of `ComplexScale(float2, float)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x84): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMultiplyAndScale(float2, float2, float)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0xa8): multiple definition of `ComplexMultiplyAndScale(float2, float2, float)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xa8): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMagnitudeSquared(float2)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0xd8): multiple definition of `ComplexMagnitudeSquared(float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xd8): first defined here
collect2: ld returned 1 exit status
make[2]: *** [tests/WienerFilterTest/WienerFilterTest] Error 1
make[1]: *** [tests/WienerFilterTest/CMakeFiles/WienerFilterTest.dir/all] Error 2
make: *** [all] Error 2
This is a pretty large project, and thus these are some intimidating errors for me. Does anyone have any idea what the problem could be? Many people have compiled this, and it's been tested on RedHat. After messing with it a few days I'm out of ideas, but I'll be happy to provide any information that might help.
Looking at the error messages posted, I would say that the #include<cstdlib> is unrelated to the second set of errors. Including cstdlib solved some compilation errors, allowing the compilation stage to complete and the linking stage to start.
The second set of errors is raised during the link stage because some functions have been defined in more than one compilation unit.
The error messages indicate that the files with the names WienerDeconvolve.cxx, WienerDeconvolveGPU.cu_Clarity_generated.cpp, and FFTGPU.cu_Clarity_generated.cpp all contain definitions for functions with the same signature: ComplexConjugate(float2), ComplexAdd(float2, float2), etc.
Bascially, when the linker finds multiple functions with the same signature, it is unsure which one to use and generates these errors. There are a number of reasons that these errors could occur, such as:
The intent was for the functions to be local to the compilation unit, but it was forgotten to declare them as static or to place them in an anonymous namespace.
The functions were defined in a header file that was included by multiple source files. See this post for more information: Link error with really simple functions C++ on .h file
What you will need to do is look through your code to find the location(s) where these multiply defined functions are being defined to determine exactly how they are being defined more than once. That information will let you determine the solution to the problem.
The normal solution I've found is to insert #include cstlib in the code, WienerDeconvolve.cxx
That part scares me. Weird wording aside, are you #includeing .cxx files? The only other way you get that error is if you have function definitions in your header, as opposed to only declarations.
Well, you could also be linking an object multiple times I guess, but I haven't yet seen someone do that :)
Related
I'm trying to run make on an Ubuntu machine to compile a RoT MUD, but the farthest I've gotten is when I get a collect2: error: ld returned 1 exit status.
This is what comes immediately before the error in the terminal (along with a lot of other similar errors):
/usr/bin/ld: obj/wizlist.o:/home/lucas/Projects/R2b5/src/merc.h:3355: multiple definition of `bllmax'; obj/act_comm.o:/home/lucas/Projects/R2b5/src/merc.h:3355: first defined here
From what I've gathered this means that the header files have variable declarations in them, and that using static is an easy fix, however, I haven't been able to figure out where I should put that keyword in the code to fix this issue. The following is the only mention of bllmax in merc.h:
int bllmax, crbmax, crnmax, srpmax, mngmax;
Here is the program I'm trying to compile.
You need to learn the difference between declaration and definition. A declaration is telling the compiler that the symbol exists somewhere but possibly not here. A definition is telling the compiler that the symbol exists here.
The line you show (without any context) is defining the variables, which means they will be defined in each source file that includes the header file.
What it should do is to declare the variables, which can be done by making them extern:
extern int bllmax, crbmax, crnmax, srpmax, mngmax;
Then in a single source file define the variables (without extern).
When I include "stdio.h" and try to use "printf" it works fine.
In the same way when I use "krb5.h", its function "krb5_get_init_creds_password" does not get resolved by its own.
Error faced :
bash-4.1$ gcc krb.c
krb.c: In function ‘main’:
krb.c:6: warning: incompatible implicit declaration of built-in function ‘printf’
/tmp/ccTK4DJM.o: In function main':
krb.c:(.text+0x53): undefined reference tokrb5_get_init_creds_password'
collect2: ld returned 1 exit status
I had to compile using -lkrb5 which resolved the issue.
Can someone let me know why do I need to use gcc option "-lkrb5" to get that krb5 function resolved ?
I am using C.
The header file you include only contains the declaration of the function, the actual function definition (the implementation) is in the actual library (usually a file named (using your example) libkrb5.a or libkrb5.so).
The option you pass to the linker is -l (lower-case L) which tells the linker to find and use whatever library you pass as argument to the -l option.
If you have create programs consisting of multiple source files yourself, then this should not have been much of a surprise really. If you have two source files a.c and b.c, where in a.c you call a function defined in b.c you need to declare the function for it to be available in a.c. And then when you link the executable program you need to link with the object file created by b.c to be able to find the definition.
Using a library is really not much different from that.
anyone can help me?? my board is LPC1768 and the sensor is BMP180
Rebuild target 'Target 1'
compiling BMP180.c...
compiling I2C.c...
assembling startup_LPC17xx.s...
compiling system_LPC17xx.c...
compiling GPIO_LPC17xx.c...
compiling PIN_LPC17xx.c...
linking...
.\Objects\asdsa.axf: Error: L6218E: Undefined symbol main (referred from __rtentry2.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 1 error messages.
".\Objects\asdsa.axf" - 1 Error(s), 0 Warning(s).
Target not created.
I found the solution is easy, but before going deeper into the solution, keep in mind that C compilation unit (C Compiler and Assembler at least) compiles each pure C source file after resolving necessary pre-processor directives, and generates a relocatable object file as a result of compilation.
After the compilation unit does its job, there is another unit that is responsible for combining individually every source file that is compiled successfully into the relocatable form of one big object file for all. This unit is called Linker and the operation is called Linking
A very important feature in relocatable object file is that what is called variable, function will be noted as symbol so far. The linker has to solve the symbols, defining what is originally defined in an object file, reference what is being used in another to their original object file.
After this motivation, now we can call main() function as main() symbol.
I Found that the problem is because the source file that contains the main() function was not compiled. As a result, there is no a relocatable object file that contains the symbol corresponding to main() function. Hence, the compiler is complaining: you asked me to use (reference) a symbol you guaranteed to be found (defined) in another file but I found no such symbol!
The solution:
For Kiel IDE, to queue a source file for a compilation; you gotta shortlist it in the category "Source Group",by clicking right, either adding new files to group, or existing files to group. It will result in something like the following figure:
Now we have a main function, is turned (defined) to main symbol later, and found by the linker to reference it to whatever use it in any other relocatable object files.
I solved this problem with the following steps;
Delete your old project and create new project
Choose true library from Manage Run Time Environment like so:
Configure "Options for Target" segment. Define symbol USE_STDPERIPH_DRIVER and define project path like so:
Test your configuration. Please write the following code:
#include "stm32f10x.h" // Device header
int main() {
}
I had the same issue. The problem was that the function name in .c file had a different name with the one in the .h file, and I didn't know.
just add your c file (ex: 'main.c') to the source group (ex: 'source group 1') by expanding the target then right click on the source group, choose add existing files to group 'your source group', then choose the main.c file.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/14222.html
This should help.
Just create a dummy main() or main.c file. Linker can't find it in your pjt.
For solution only add this file C to driver folder and translate it,
Solved: This "Target Not Created" Issue was Resolved by the setting of Run Time Environment as shown in below(url) image.https://i.stack.imgur.com/kJ4IL.jpg ( consisting of CMSIS and Device supporting components in Run time environment)
{ compiling TransformFunctions.c...
linking...
Program Size: Code=768 RO-data=320 RW-data=4 ZI-data=612
FromELF: creating hex file...
".\Objects\LPC1768_B_T.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:07
}
I am new to linux, C and stack overflow. I was trying to view page tables of all processes running. For this I am using dump_pagetable.c.
I tried to run first by normal compiling gcc dump_pagetables.c -o dump_pagetables.out. But it gave me error:
dump_pagetable.c:15:27: fatal error: linux/debugfs.h: No such file or directory #include linux/debugfs.h></code><br/><br/>Then I tried to use a make command <code>make -C /lib/modules/$(uname -r)/build M=$PWD modules</code>. So it gave me this error<code>CC [M] /home/varma/Desktop/TLB/dump_pagetable.o
/home/varma/Desktop/TLB/dump_pagetable.c:420:1: warning: data definition has no type or storage class
__initcall(pt_dump_init);
^
/home/varma/Desktop/TLB/dump_pagetable.c:420:1: error: type defaults to ‘int’ in declaration of ‘__initcall’ [-Werror=implicit-int]
/home/varma/Desktop/TLB/dump_pagetable.c:420:1: warning: parameter names (without types) in function declaration
/home/varma/Desktop/TLB/dump_pagetable.c:398:12: warning: ‘pt_dump_init’ defined but not used [-Wunused-function]
static int pt_dump_init(void)
^
cc1: some warnings being treated as errors
scripts/Makefile.build:263: recipe for target '/home/varma/Desktop/TLB/dump_pagetable.o' failed
make[1]: *** [/home/varma/Desktop/TLB/dump_pagetable.o] Error 1
Makefile:1394: recipe for target '_module_/home/varma/Desktop/TLB' failed
make: *** [_module_/home/varma/Desktop/TLB] Error 2
make: Leaving directory '/usr/src/linux-headers-3.19.0-23-generic'</code>
How do I get this code running?
How do modify the dump_pagetables.c So that I can see huge pages also.
The file you are trying to compile is a utility function for use within the Linux kernel for a somewhat obscure CPU used in IBM mainframes (the IBM System/390). It cannot be used outside of the kernel, and even there, it's only applicable to systems of that particular architecture, not to any desktop computers.
Needless to say, this won't work.
There is an equivalent feature (CONF_X86_PTDUMP) available in the kernel for x86 systems, but it is not enabled. If you want to use it, you will probably need to recompile your kernel. For more details, see the answer to the question "Print kernel's page tables".
I am trying to create a makefile and was able to get all of the files to compile but it fails on the linker step. Every function in the project is getting an error where it says GCC multiple definition of 'Function Name' then claims that it was first defined in the exact same spot. For example...
project/src/provCreator.o: In function `ProcessArgs':
/home/kevin/project/src/provCreator.c:380: multiple definition of `ProcessArgs'
project/src/provCreator.o:/home/kevin/project/src/provCreator.c:380: first defined here
What are possible causes of this error and how can it be fixed?
Thank you for helping.
Your makefile has project/src/provCreator.c file listed twice. Possibly, with different relative paths.
From your description, it seems that all c files are listed twice (ctrl-c/ctrl-v error?)
Any linker throws a multiple definition error while functions with the same name compiled or same function compiled multiple times due to duplicate listings in makefile. After compilation, while linking linker will be in confusion which object definition it has to link hence it throws an error.
In your case, please check your makefile, probably you might have listed provCreator.c twice.