I know this has been asked a thousands times, but I'm stumped. I've been looking all over for that last 3 days without a result. I keep getting this error and I can't figure out why.
I've added only the code that I have input / that matters. If I comment out my code the program compiles without a problem. What am I doing wrong???
CMakeFiles/brewtarget.dir/MainWindow.cpp.o: In function MainWindow::MainWindow(QWidget*)':
MainWindow.cpp:(.text+0xb145): undefined reference to yeastCellCounter::yeastCellCounter()'
CODE
mainwindow.cpp
#include "yeastcellcounter.h"
// a whole lot of stuff between these...
yeastCountDialog = new yeastCellCounter();
mainwindow.h
class yeastCellCounter;
// A whole log of stuff between these...
yeastCellCounter *yeastCountDialog;
yeascellcounter.cpp
#include "yeastcellcounter.h"
yeastCellCounter::yeastCellCounter(){}
yeastcellcounter.h
#ifndef YEASTCELLCOUNTER_H
#define YEASTCELLCOUNTER_H
class yeastCellCounter
{
public:
yeastCellCounter();
};
#endif // YEASTCELLCOUNTER_H
This are the INCLUDE_DIRECTORIES directive in cmakelist.txt
SET(ROOTDIR "${CMAKE_CURRENT_SOURCE_DIR}")
SET(SRCDIR "${ROOTDIR}/src")
SET(UIDIR "${ROOTDIR}/ui")
SET(DATADIR "${ROOTDIR}/data")
SET(TRANSLATIONSDIR "${ROOTDIR}/translations")
SET(WINDIR "${ROOTDIR}/win")
INCLUDE_DIRECTORIES(${SRCDIR})
INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/src") # In case of out-of-source build.
INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/QtDesignerPlugins")
Whenever you see a error of the type undefined reference to ... it is a linker error. This means that the compiler has completed it's work and all the object files have been compiled without errors. It's now time for the linker to put all the pieces together into a single file.
In your specific example, it says that it cannot find the definition of the function yeastCellCounter::yeastCellCounter(). From the code you have pasted, this function, albeit empty, is clearly defined in the file yeascellcounter.cpp.
It looks like your cmakelists.txt file is incomplete. You haven't specified which source files need to be linked together to create your final executable. You need to use the add_executable statement for this.
Here's a simple example
The problem is:
yeastCountDialog = new yeastCellCounter();
It should be:
yeastCountDialog = new yeastCellCounter;
(Notice the lack of parentheses). The default constructor is always called without parentheses. And also, you need to add "yeastcellcounter.cpp" to the list of cmake sources.
Related
there is something that has been bugging me for a while.
I cannot create a destructor using Xcode (with other IDEs like VS2021 that is no issue).
I get the error:
1. Constructor cannot be redeclared
2. Missing return type for function '˜Pointer'; did you mean the constructor name 'Pointer'?
If I try to declare outside of the class and uncomment the lines in *.cpp and *.hpp the errors get even crazier.
My Pointers.hpp is the following:
#ifndef Pointers_hpp
#define Pointers_hpp
#include <iostream>
class Pointer{
public:
Pointer(void);
˜Pointer(void){};
//˜Pointer(void);
};
#endif /* Pointers_hpp */
and my Pointers.cpp is this one:
#include "Pointers.hpp"
Pointer::Pointer(void){};
//Pointer::˜Pointer(void){};
After several research in the internet, I could not find a solution to that, could any one give me a light on this?
Many thanks in advance,
Raphael
Solved thanks to user4581301:
For those having the same problem I did.
The issue here was the similarity between ˜ and ~
The correct one should be ~
If you are using MacBook Pro the short-key is Option-N.
I am trying to write an LLVM backend, when I am trying to build it, I get the following error message:
AbcGenRegisterInfo.inc: In static member function 'static const llvm::AbcFrameLowering* llvm::AbcGenRegisterInfo::getFrameLowering(const llvm::MachineFunction&)':
AbcGenRegisterInfo.inc:322:43: error: invalid static_cast from type 'const llvm::TargetFrameLowering*' to type 'const llvm::AbcFrameLowering*'
MF.getSubtarget().getFrameLowering());
^
Here is my AbcRegisterInfo.td (I copied it from here):
class AbcReg<string n> : Register<n> {
let namespace = "Abc";
}
def DUMMY_REG : AbcReg<"R0">;
def RegI64 : RegisterClass<"Abc", [i64], 64, (add DUMMY_REG)>;
I also overrided AbcSubtarget::getFrameLowering() method:
class AbcSubTarget : public AbcGenSubtargetInfo {
AbcFrameLowering *frameLowering;
// more fields and methods
const AbcFrameLowering *getFrameLowering() const override {
return frameLowering;
}
};
but the error message did not change.
I don't understand what to do - I can't just edit AbcGenRegisterInfo.inc, because it will be re-generated every time I will build LLVM, and I don't understand what's wrong in my TableGen files.
I also tried to remove AbcGenRegisterInfo.inc file from my build directory before compiling, but it had no effect.
Does AbcFrameLowering inherit from TargetFrameLowering? It looks like the static cast is complaining because the types are unrelated.
Also make sure the header with the definition of AbcFrameLowering is included before the .inc file is included otherwise the static cast will fail as well.
I have the same exact error, and while I cannot answer your question in full, I believe I can address one part of the issue. You said
I also tried to remove AbcGenRegisterInfo.inc file from my build directory before compiling, but it had no effect.
Unless you mean that AbcGenRegisterInfo.inc was regenerated (and therefore deleting it had no effect), the fact that its absence has no effect should be due to the fact that TableGen has the .inc.tmp file to rely on as a backup. I noticed that when I make with VERBOSE=1, there is a statement that suggests tablegen uses the .tmp files in this way.
Again, not a specific answer to your main question, but just to hopefully help address that issue when trying to debug.
I am using XE3 and trying to construct a DLL with my third party component. Since it is a rather large project I will describe it then detail the question at hand.
I have multiple cpp files and multiple header files(classes in header files, functions in cpp files). I have everything linking and compiling fine UNTIL I put a CreateWnd() function into one of my classes
void __fastcall TICSByteEntry::CreateWnd(void)
{
TCustomControl::CreateWnd();
SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) | WS_CLIPSIBLINGS);
}
Now it will compile with this code in it but when I put my component on a form and try to run THAT project it will give me an error
'[ilink32 error] Error: Unresolved external '__fastcall TICSByteEntry::CreateWnd() referenced from 'path'unit1.obj'
No other linking issues just that one and as soon as I comment it out everything works nicely as expected. When I was researching this online someone said it is having problems finding the entry point http://edn.embarcadero.com/article/27343. I tried what was recommended and no luck. Any one want to take a guess on what is wrong?
Instead of overriding CreateWnd() you should override CreateParams(). That way the window is created with the style you want and does not need to be changed after creation.
I ran into a problem with the Eclipse formatter. It won't format my code correctly when declaring methods within a class declaration. It puts a new line after the method's return type.
I already exported the style xml file and examined the settings in it, but none of the settings have any apparent connection to this problem, and the settings editor in Eclipse didn't show the same problem happening in it's sample code for method declarations.
Here is an example bit of code for what I want to have happen:
class MyClass
{
public:
MyClass();
void myMethod();
};
However, this is what I get:
class MyClass
{
public:
MyClass();
void
myMethod();
};
Again, in the styles editor, the code doesn't have this problem and looks just how I want it to, but in the actual code, the story is different.
I'm using version 3.8.0. Any help is appreciated.
Edit: I deleted those source files that were formatted incorrectly (after formatting the code several times to no avail) and replaced them with "identical" files with the same methods, same structure, etc. I formatted the code this time and it worked. This is probably a bug, but I'm leaving it up just in case anyone else encounters a similar problem or has a solution to avoiding this problem in the first place.
I hand edited two files under the main eclipse projects directory
.metadata\.plugins\org.eclipse.core.runtime\.settings
The two files:
file 1: org.eclipse.cdt.core.prefs, change this line from "insert" to "do not insert"
org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration=do not insert
file 2: org.eclipse.cdt.ui.prefs,
scan this file for "insert_new_line_before_identifier_in_function_declaration" and make a similar change from insert to do not insert next to it, should be obvious
Note I seen this problem on indigo and juno, the fix described above was in juno.
If you have a custom formatter config, export it first (settings>C/C++ General>Formatter>Edit>Export). Then change the following line to "do not insert". Save the XML.
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration" value="do not insert"/>
Delete the current config and import the one you changed.
There's a specific preference in the formatter options starting from cdt 9.8 included in Eclipse 2019-06.
I know that all forums are full of such question, but I've tried few hooks, and they doesn't work (or I do them bad).
So, I've got:
main.cpp <- fawn.h <- connector.cpp (defenition) <- conncetor.h (declaration)
<- portl.cpp (def) <- portl.h (dcl) <- connector.h
with include guard (thanks to Igor Zevaka and jk), everything compiles, but doesn't link,
saying "already defined in main.obj" about all funcs., no metter are they static or not.
I've tryed already pulling the conncetor.h contents to connector.cpp, same way with portl.cpp (there was #include "connector.h" in it).
Thanks beforehand.
Does fawn.h include connector.cpp? (or do I read it wrong?)
If so this is your error. Now connector.cpp (itself) has a function bla() and main.cpp has same function because it includes (read: copy-pasted in) connector.cpp. And you are trying to link them together.
EDIT:
For the last error make sure FAWN::Sys::Connecter::getSocket(void) is implemented somewhere (and that cpp file it is in is linked in). Looks like it is just missing.
Make sure that you link properly against the required libraries of boost...
Check the dependencies here:
http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/using.html