Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple definition error for CORS middleware #390

Closed
cdwdong opened this issue Apr 7, 2022 · 5 comments · Fixed by #395
Closed

multiple definition error for CORS middleware #390

cdwdong opened this issue Apr 7, 2022 · 5 comments · Fixed by #395
Labels
bug Something isn't working

Comments

@cdwdong
Copy link

cdwdong commented Apr 7, 2022

Can't not build in linking parse cause multiple definition.

linker log :

1>Linking objects
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\obj\x64\Debug\WebService.o : error : In function `crow::CORSRules::prefix(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\crow_all.h(11053): error : multiple definition of `crow::CORSRules::prefix(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\obj\x64\Debug\main.o : error : /home/kai/projects/TestProject_App/crow_all.h:11053: first defined here
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\obj\x64\Debug\WebService.o : error : In function `crow::CORSRules::blueprint(crow::Blueprint const&)':
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\crow_all.h(11058): error : multiple definition of `crow::CORSRules::blueprint(crow::Blueprint const&)'
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\obj\x64\Debug\main.o : error : /home/kai/projects/TestProject_App/crow_all.h:11058: first defined here
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\obj\x64\Debug\WebService.o : error : In function `crow::CORSRules::global()':
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\crow_all.h(11063): error : multiple definition of `crow::CORSRules::global()'
1>D:\dev\office_work\TestProject_App_Linux\TestProject_Linux\obj\x64\Debug\main.o : error : /home/kai/projects/TestProject_App/crow_all.h:11063: first defined here
1>collect2 : error : ld returned 1 exit status
1>Done building project "TestProject_Linux.vcxproj" -- FAILED.

It was build in gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
I use MSBuild c++ cross platform compile.
crow version is v1.0+1 Hotfix

@cdwdong cdwdong changed the title Can' t not build in link parse cause multiple definition. Can't not build in link parse cause multiple definition. Apr 7, 2022
@cdwdong cdwdong changed the title Can't not build in link parse cause multiple definition. Can't not build in linking parse cause multiple definition. Apr 7, 2022
@The-EDev
Copy link
Member

The-EDev commented Apr 7, 2022

@dranikpg It seems the CORS middleware isn't designed to work with multiple source files, I'll try to look into it but I'd be thankful for help.

@The-EDev The-EDev added the bug Something isn't working label Apr 7, 2022
@The-EDev The-EDev changed the title Can't not build in linking parse cause multiple definition. multiple definition error for CORS middleware Apr 7, 2022
@jeanbiber
Copy link

jeanbiber commented Apr 7, 2022

I had yesterday the same issue. My solution was to write "inline" before the functions-impementations and it worked for me.
cors.h: from line 185

inline CORSRules& CORSRules::prefix(const std::string& prefix)
{
return handler_->prefix(prefix);
}

inline CORSRules& CORSRules::blueprint(const Blueprint& bp)
{
    return handler_->blueprint(bp);
}

inline CORSRules& CORSRules::global()
{
    return handler_->global();
}

@The-EDev
Copy link
Member

The-EDev commented Apr 7, 2022

The issue is that the declaration and definitions for CORSRules are separate, and so the definitions get repeated when using more than 1 source file.

@jeanbiber
Copy link

jeanbiber commented Apr 7, 2022

I mean that Inside the class a declaration is considered to be inline by the compiler. If you implement outside of body, but still in header, you have to mark the method as 'inline' explicitly.

struct CORSRules
 {
      /// Handle CORS for specific blueprint
      CORSRules& blueprint(const Blueprint& bp);
}
inline CORSRules& CORSRules::blueprint(const Blueprint& bp)
{
    return handler_->blueprint(bp);
}

@dranikpg
Copy link
Member

dranikpg commented Apr 8, 2022

Sorry for the late response. I must have missed this when refactoring them out of the class.
Thanks for pointing out the fix! 👍🏻

@The-EDev The-EDev linked a pull request Apr 8, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants